diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index fad6917358..8d5aaaedeb 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -249,6 +249,22 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { return parseVerifyNavTree(callExpression.arguments); case "navigationBar": return []; // Deprecated. + case "numberOfErrorsInCurrentFile": + return parseNumberOfErrorsInCurrentFile(callExpression.arguments); + case "noErrors": + return [{ kind: "verifyNoErrors" }]; + case "errorExistsAtRange": + return parseErrorExistsAtRange(callExpression.arguments); + case "currentLineContentIs": + return parseCurrentLineContentIs(callExpression.arguments); + case "currentFileContentIs": + return parseCurrentFileContentIs(callExpression.arguments); + case "errorExistsBetweenMarkers": + return parseErrorExistsBetweenMarkers(callExpression.arguments); + case "errorExistsAfterMarker": + return parseErrorExistsAfterMarker(callExpression.arguments); + case "errorExistsBeforeMarker": + return parseErrorExistsBeforeMarker(callExpression.arguments); } } // `goTo....` @@ -313,6 +329,32 @@ function parseEditStatement(funcName: string, args: readonly ts.Expression[]): E goStatement: `f.Backspace(t, 1)`, }; } + case "deleteAtCaret": { + const arg = args[0]; + if (arg) { + let arg0; + if (arg0 = getNumericLiteral(arg)) { + return { + kind: "edit", + goStatement: `f.DeleteAtCaret(t, ${arg0.text})`, + }; + } + // Handle 'string'.length expressions + const lengthValue = getStringLengthExpression(arg); + if (lengthValue !== undefined) { + return { + kind: "edit", + goStatement: `f.DeleteAtCaret(t, ${lengthValue})`, + }; + } + console.error(`Expected numeric literal argument in edit.deleteAtCaret, got ${arg.getText()}`); + return undefined; + } + return { + kind: "edit", + goStatement: `f.DeleteAtCaret(t, 1)`, + }; + } default: console.error(`Unrecognized edit function: ${funcName}`); return undefined; @@ -1446,6 +1488,130 @@ function parseExpectedDiagnostic(expr: ts.Expression): string | undefined { return `&lsproto.Diagnostic{\n${diagnosticProps.join("\n")}\n}`; } +function parseNumberOfErrorsInCurrentFile(args: readonly ts.Expression[]): [VerifyNumberOfErrorsInCurrentFileCmd] | undefined { + let arg0; + if (args.length !== 1 || !(arg0 = getNumericLiteral(args[0]))) { + console.error(`Expected a single numeric literal argument in verify.numberOfErrorsInCurrentFile, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "verifyNumberOfErrorsInCurrentFile", + expectedCount: parseInt(arg0.text, 10), + }]; +} + +function parseErrorExistsAtRange(args: readonly ts.Expression[]): [VerifyErrorExistsAtRangeCmd] | undefined { + if (args.length < 2 || args.length > 3) { + console.error(`Expected 2 or 3 arguments in verify.errorExistsAtRange, got ${args.length}`); + return undefined; + } + + // First arg is a range + const rangeArg = parseBaselineMarkerOrRangeArg(args[0]); + if (!rangeArg) { + console.error(`Expected range argument in verify.errorExistsAtRange, got ${args[0].getText()}`); + return undefined; + } + + // Second arg is error code + let codeArg; + if (!(codeArg = getNumericLiteral(args[1]))) { + console.error(`Expected numeric literal for code in verify.errorExistsAtRange, got ${args[1].getText()}`); + return undefined; + } + + // Third arg is optional message + let message = ""; + if (args[2]) { + const messageArg = getStringLiteralLike(args[2]); + if (!messageArg) { + console.error(`Expected string literal for message in verify.errorExistsAtRange, got ${args[2].getText()}`); + return undefined; + } + message = messageArg.text; + } + + return [{ + kind: "verifyErrorExistsAtRange", + range: rangeArg, + code: parseInt(codeArg.text, 10), + message: message, + }]; +} + +function parseCurrentLineContentIs(args: readonly ts.Expression[]): [VerifyCurrentLineContentIsCmd] | undefined { + let arg0; + if (args.length !== 1 || !(arg0 = getStringLiteralLike(args[0]))) { + console.error(`Expected a single string literal argument in verify.currentLineContentIs, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "verifyCurrentLineContentIs", + text: arg0.text, + }]; +} + +function parseCurrentFileContentIs(args: readonly ts.Expression[]): [VerifyCurrentFileContentIsCmd] | undefined { + let arg0; + if (args.length !== 1 || !(arg0 = getStringLiteralLike(args[0]))) { + console.error(`Expected a single string literal argument in verify.currentFileContentIs, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "verifyCurrentFileContentIs", + text: arg0.text, + }]; +} + +function parseErrorExistsBetweenMarkers(args: readonly ts.Expression[]): [VerifyErrorExistsBetweenMarkersCmd] | undefined { + if (args.length !== 2) { + console.error(`Expected 2 arguments in verify.errorExistsBetweenMarkers, got ${args.length}`); + return undefined; + } + let startMarker, endMarker; + if (!(startMarker = getStringLiteralLike(args[0])) || !(endMarker = getStringLiteralLike(args[1]))) { + console.error(`Expected string literal arguments in verify.errorExistsBetweenMarkers, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "verifyErrorExistsBetweenMarkers", + startMarker: startMarker.text, + endMarker: endMarker.text, + }]; +} + +function parseErrorExistsAfterMarker(args: readonly ts.Expression[]): [VerifyErrorExistsAfterMarkerCmd] | undefined { + let markerName = ""; + if (args.length > 0) { + const arg0 = getStringLiteralLike(args[0]); + if (!arg0) { + console.error(`Expected string literal argument in verify.errorExistsAfterMarker, got ${args[0].getText()}`); + return undefined; + } + markerName = arg0.text; + } + return [{ + kind: "verifyErrorExistsAfterMarker", + markerName: markerName, + }]; +} + +function parseErrorExistsBeforeMarker(args: readonly ts.Expression[]): [VerifyErrorExistsBeforeMarkerCmd] | undefined { + let markerName = ""; + if (args.length > 0) { + const arg0 = getStringLiteralLike(args[0]); + if (!arg0) { + console.error(`Expected string literal argument in verify.errorExistsBeforeMarker, got ${args[0].getText()}`); + return undefined; + } + markerName = arg0.text; + } + return [{ + kind: "verifyErrorExistsBeforeMarker", + markerName: markerName, + }]; +} + function stringToTristate(s: string): string { switch (s) { case "true": @@ -2689,6 +2855,48 @@ interface VerifyNavTreeCmd { kind: "verifyNavigationTree"; } +interface VerifyNumberOfErrorsInCurrentFileCmd { + kind: "verifyNumberOfErrorsInCurrentFile"; + expectedCount: number; +} + +interface VerifyNoErrorsCmd { + kind: "verifyNoErrors"; +} + +interface VerifyErrorExistsAtRangeCmd { + kind: "verifyErrorExistsAtRange"; + range: string; + code: number; + message: string; +} + +interface VerifyCurrentLineContentIsCmd { + kind: "verifyCurrentLineContentIs"; + text: string; +} + +interface VerifyCurrentFileContentIsCmd { + kind: "verifyCurrentFileContentIs"; + text: string; +} + +interface VerifyErrorExistsBetweenMarkersCmd { + kind: "verifyErrorExistsBetweenMarkers"; + startMarker: string; + endMarker: string; +} + +interface VerifyErrorExistsAfterMarkerCmd { + kind: "verifyErrorExistsAfterMarker"; + markerName: string; +} + +interface VerifyErrorExistsBeforeMarkerCmd { + kind: "verifyErrorExistsBeforeMarker"; + markerName: string; +} + type Cmd = | VerifyCompletionsCmd | VerifyApplyCodeActionFromCompletionCmd @@ -2715,7 +2923,15 @@ type Cmd = | VerifyImportFixModuleSpecifiersCmd | VerifyDiagnosticsCmd | VerifyBaselineDiagnosticsCmd - | VerifyOutliningSpansCmd; + | VerifyOutliningSpansCmd + | VerifyNumberOfErrorsInCurrentFileCmd + | VerifyNoErrorsCmd + | VerifyErrorExistsAtRangeCmd + | VerifyCurrentLineContentIsCmd + | VerifyCurrentFileContentIsCmd + | VerifyErrorExistsBetweenMarkersCmd + | VerifyErrorExistsAfterMarkerCmd + | VerifyErrorExistsBeforeMarkerCmd; function generateVerifyOutliningSpans({ foldingRangeKind }: VerifyOutliningSpansCmd): string { if (foldingRangeKind) { @@ -3029,6 +3245,22 @@ function generateCmd(cmd: Cmd): string { return generateVerifyOutliningSpans(cmd); case "verifyNavigationTree": return `f.VerifyBaselineDocumentSymbol(t)`; + case "verifyNumberOfErrorsInCurrentFile": + return `f.VerifyNumberOfErrorsInCurrentFile(t, ${cmd.expectedCount})`; + case "verifyNoErrors": + return `f.VerifyNoErrors(t)`; + case "verifyErrorExistsAtRange": + return `f.VerifyErrorExistsAtRange(t, ${cmd.range}, ${cmd.code}, ${getGoStringLiteral(cmd.message)})`; + case "verifyCurrentLineContentIs": + return `f.VerifyCurrentLineContentIs(t, ${getGoStringLiteral(cmd.text)})`; + case "verifyCurrentFileContentIs": + return `f.VerifyCurrentFileContentIs(t, ${getGoStringLiteral(cmd.text)})`; + case "verifyErrorExistsBetweenMarkers": + return `f.VerifyErrorExistsBetweenMarkers(t, ${getGoStringLiteral(cmd.startMarker)}, ${getGoStringLiteral(cmd.endMarker)})`; + case "verifyErrorExistsAfterMarker": + return `f.VerifyErrorExistsAfterMarker(t, ${getGoStringLiteral(cmd.markerName)})`; + case "verifyErrorExistsBeforeMarker": + return `f.VerifyErrorExistsBeforeMarker(t, ${getGoStringLiteral(cmd.markerName)})`; default: let neverCommand: never = cmd; throw new Error(`Unknown command kind: ${neverCommand as Cmd["kind"]}`); @@ -3047,16 +3279,17 @@ function generateGoTest(failingTests: Set, test: GoTest, isServer: boole const commands = test.commands.map(cmd => generateCmd(cmd)).join("\n"); const imports = [`"github.com/microsoft/typescript-go/internal/fourslash"`]; // Only include these imports if the commands use them to avoid unused import errors. - if (commands.includes("core.")) { + // Use regex with word boundary to avoid false positives like "underscore." matching "core." + if (/\bcore\./.test(commands)) { imports.unshift(`"github.com/microsoft/typescript-go/internal/core"`); } - if (commands.includes("ls.")) { + if (/\bls\./.test(commands)) { imports.push(`"github.com/microsoft/typescript-go/internal/ls"`); } - if (commands.includes("lsutil.")) { + if (/\blsutil\./.test(commands)) { imports.push(`"github.com/microsoft/typescript-go/internal/ls/lsutil"`); } - if (commands.includes("lsproto.")) { + if (/\blsproto\./.test(commands)) { imports.push(`"github.com/microsoft/typescript-go/internal/lsp/lsproto"`); } if (usesFourslashUtil(commands)) { @@ -3129,6 +3362,17 @@ function getArrayLiteralExpression(node: ts.Node): ts.ArrayLiteralExpression | u return getNodeOfKind(node, ts.isArrayLiteralExpression); } +// Parses expressions like 'string'.length or "string".length and returns the length value +function getStringLengthExpression(node: ts.Node): number | undefined { + if (ts.isPropertyAccessExpression(node) && node.name.text === "length") { + const stringLiteral = getStringLiteralLike(node.expression); + if (stringLiteral) { + return stringLiteral.text.length; + } + } + return undefined; +} + function getInitializer(name: ts.Identifier): ts.Expression | undefined { const file = name.getSourceFile(); const varStmts = file.statements.filter(ts.isVariableStatement); diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 297cda0537..be20094672 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -1,8 +1,10 @@ TestAliasMergingWithNamespace +TestAllowLateBoundSymbolsOverwriteEarlyBoundSymbols TestAmbientShorthandGotoDefinition TestArgumentsAreAvailableAfterEditsAtEndOfFunction TestAugmentedTypesClass1 TestAugmentedTypesClass3Fourslash +TestAutoFormattingOnPasting TestAutoImportAllowImportingTsExtensionsPackageJsonImports1 TestAutoImportCompletionAmbientMergedModule1 TestAutoImportCompletionExportListAugmentation1 @@ -47,6 +49,7 @@ TestAutoImportVerbatimTypeOnly1 TestBestCommonTypeObjectLiterals TestBestCommonTypeObjectLiterals1 TestCalledUnionsOfDissimilarTyeshaveGoodDisplay +TestCloduleTypeOf1 TestCodeCompletionEscaping TestCommentsEnumsFourslash TestCommentsExternalModulesFourslash @@ -59,6 +62,7 @@ TestCommentsUnion TestCommentsVariables TestCompletionAfterQuestionDot TestCompletionAutoInsertQuestionDot +TestCompletionBeforeSemanticDiagnosticsInArrowFunction1 TestCompletionCloneQuestionToken TestCompletionEntryClassMembersWithInferredFunctionReturnType1 TestCompletionEntryForArgumentConstrainedToString @@ -237,17 +241,49 @@ TestCompletionsWithDeprecatedTag10 TestCompletionWithConditionalOperatorMissingColon TestConstEnumQuickInfoAndCompletionList TestConstQuickInfoAndCompletionList +TestConstructorBraceFormatting TestContextuallyTypedFunctionExpressionGeneric1 +TestContextualTypingOfGenericCallSignatures2 TestCrossFileQuickInfoExportedTypeDoesNotUseImportType TestDoubleUnderscoreCompletions +TestDuplicatePackageServices TestEditJsdocType +TestErrorsAfterResolvingVariableDeclOfMergedVariableAndClassDecl TestExportDefaultClass TestExportDefaultFunction +TestExportEqualTypes +TestFindAllRefs_importType_js1 +TestFindAllRefs_importType_js2 +TestFindAllRefs_importType_js3 TestFindReferencesBindingPatternInJsdocNoCrash1 TestFindReferencesBindingPatternInJsdocNoCrash2 +TestFormatAfterWhitespace +TestFormatAnyTypeLiteral +TestFormatEmptyBlock +TestFormatEmptyParamList +TestFormatonkey01 +TestFormatOnSemiColonAfterBreak +TestFormattingAfterMultiLineIfCondition +TestFormattingBlockInCaseClauses +TestFormattingEqualsBeforeBracketInTypeAlias +TestFormattingIfInElseBlock +TestFormattingInExpressionsInTsx +TestFormattingOfChainedLambda +TestFormattingOnCloseBrace +TestFormattingOnDoWhileNoSemicolon +TestFormattingOnEnter +TestFormattingOnNestedDoWhileByEnter +TestFormattingOnSemiColon +TestFormattingSpaceAfterCommaBeforeOpenParen +TestFormattingTemplates +TestFormattingWithMultilineComments +TestFunctionTypeFormatting +TestFunduleWithRecursiveReference TestGenericCombinators3 TestGenericCombinatorWithConstraints1 TestGenericFunctionWithGenericParams1 +TestGenericInterfacePropertyInference1 +TestGenericInterfacePropertyInference2 TestGenericInterfacesWithConstraints1 TestGenericTypeWithMultipleBases1MultiFile TestGetJavaScriptCompletions10 @@ -288,6 +324,7 @@ TestImportCompletionsPackageJsonImportsPattern_ts TestImportCompletionsPackageJsonImportsPattern_ts_ts TestImportCompletionsPackageJsonImportsPattern2 TestImportFixesGlobalTypingsCache +TestImportMetaCompletionDetails TestImportNameCodeFix_avoidRelativeNodeModules TestImportNameCodeFix_fileWithNoTrailingNewline TestImportNameCodeFix_HeaderComment1 @@ -336,6 +373,7 @@ TestIndexerReturnTypes1 TestIndirectClassInstantiation TestInstanceTypesForGenericType1 TestJavascriptModules20 +TestJavascriptModules24 TestJsDocAugments TestJsDocAugmentsAndExtends TestJsdocCallbackTag @@ -379,7 +417,9 @@ TestMemberListInReopenedEnum TestMemberListInWithBlock TestMemberListOfExportedClass TestMemberListOnContextualThis +TestMultiModuleFundule TestNgProxy1 +TestNgProxy4 TestNodeModulesImportCompletions1 TestNoQuickInfoForLabel TestNoQuickInfoInWhitespace @@ -387,6 +427,7 @@ TestNumericPropertyNames TestOverloadQuickInfo TestParameterWithDestructuring TestParameterWithNestedDestructuring +TestPaste TestPathCompletionsAllowModuleAugmentationExtensions TestPathCompletionsAllowTsExtensions TestPathCompletionsPackageJsonExportsBundlerNoNodeCondition @@ -444,6 +485,7 @@ TestQuickInfoAssertionNodeNotReusedWhenTypeNotEquivalent1 TestQuickInfoBindingPatternInJsdocNoCrash1 TestQuickInfoCanBeTruncated TestQuickInfoClassKeyword +TestQuickInfoCloduleWithRecursiveReference TestQuickInfoContextuallyTypedSignatureOptionalParameterFromIntersection1 TestQuickInfoContextualTyping TestQuickInfoDisplayPartsIife @@ -475,6 +517,7 @@ TestQuickInfoInJsdocInTsFile1 TestQuickInfoInOptionalChain TestQuickInfoInWithBlock TestQuickInfoJSDocBackticks +TestQuickInfoJsdocEnum TestQuickInfoJSDocFunctionNew TestQuickInfoJSDocFunctionThis TestQuickInfoJsDocGetterSetterNoCrash1 @@ -484,6 +527,7 @@ TestQuickInfoJSExport TestQuickInfoMappedSpreadTypes TestQuickInfoMappedType TestQuickInfoMappedTypeRecursiveInference +TestQuickInfoMeaning TestQuickInfoModuleVariables TestQuickInfoNarrowedTypeOfAliasSymbol TestQuickInfoNestedGenericCalls @@ -504,6 +548,8 @@ TestQuickInfoOnFunctionPropertyReturnedFromGenericFunction3 TestQuickInfoOnGenericWithConstraints1 TestQuickInfoOnInternalAliases TestQuickInfoOnJsxNamespacedNameWithDoc1 +TestQuickInfoOnMergedInterfacesWithIncrementalEdits +TestQuickInfoOnMergedModule TestQuickInfoOnMethodOfImportEquals TestQuickInfoOnNarrowedTypeInModule TestQuickInfoOnNewKeyword01 @@ -538,6 +584,7 @@ TestQuickInfoTypeError TestQuickInfoTypeOfThisInStatics TestQuickInfoTypeOnlyNamespaceAndClass TestQuickInfoUnionOfNamespaces +TestQuickInfoUntypedModuleImport TestQuickInfoWidenedTypes TestQuickinfoWrongComment TestRecursiveInternalModuleImport @@ -550,11 +597,17 @@ TestRenameFromNodeModulesDep4 TestRenamePrivateFields TestReverseMappedTypeQuickInfo TestSelfReferencedExternalModule +TestSemicolonFormatting +TestSemicolonFormattingAfterArrayLiteral +TestSemicolonFormattingNestedStatements +TestSignatureHelpCallExpressionJs +TestSpaceAfterConstructor TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestSymbolCompletionLowerPriority TestSyntheticImportFromBabelGeneratedFile1 TestSyntheticImportFromBabelGeneratedFile2 +TestTabbingAfterNewlineInsertedBeforeWhile TestThisBindingInLambda TestThisPredicateFunctionQuickInfo01 TestThisPredicateFunctionQuickInfo02 @@ -570,4 +623,10 @@ TestTsxQuickInfo4 TestTsxQuickInfo5 TestTsxQuickInfo6 TestTsxQuickInfo7 +TestTypeCheckAfterResolve TestTypeOperatorNodeBuilding +TestUnclosedStringLiteralAutoformating +TestWhiteSpaceBeforeReturnTypeFormatting +TestWhiteSpaceTrimming +TestWhiteSpaceTrimming2 +TestWhiteSpaceTrimming4 diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 0cb444b9ff..488c0beff8 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -2548,6 +2548,17 @@ func (f *FourslashTest) Backspace(t *testing.T, count int) { // f.checkPostEditInvariants() // !!! do we need this? } +// DeleteAtCaret removes the text at the current caret position as if the user pressed delete `count` times. +func (f *FourslashTest) DeleteAtCaret(t *testing.T, count int) { + script := f.getScriptInfo(f.activeFilename) + offset := int(f.converters.LineAndCharacterToPosition(script, f.currentCaretPosition)) + + for range count { + f.editScriptAndUpdateMarkers(t, f.activeFilename, offset, offset+1, "") + // Position stays the same after delete (unlike backspace) + } +} + // Enters text as if the user had pasted it. func (f *FourslashTest) Paste(t *testing.T, text string) { script := f.getScriptInfo(f.activeFilename) @@ -3848,3 +3859,170 @@ func collectDocumentSymbolSpans( } } } + +// VerifyNumberOfErrorsInCurrentFile verifies that the current file has the expected number of errors. +func (f *FourslashTest) VerifyNumberOfErrorsInCurrentFile(t *testing.T, expectedCount int) { + diagnostics := f.getDiagnostics(t, f.activeFilename) + // Filter to only include errors (not suggestions/hints) + errors := core.Filter(diagnostics, func(d *lsproto.Diagnostic) bool { + return !isSuggestionDiagnostic(d) + }) + if len(errors) != expectedCount { + t.Fatalf("Expected %d errors in current file, but got %d", expectedCount, len(errors)) + } +} + +// VerifyNoErrors verifies that no errors exist in any open files. +func (f *FourslashTest) VerifyNoErrors(t *testing.T) { + for fileName := range f.openFiles { + diagnostics := f.getDiagnostics(t, fileName) + // Filter to only include errors (not suggestions/hints) + errors := core.Filter(diagnostics, func(d *lsproto.Diagnostic) bool { + return !isSuggestionDiagnostic(d) + }) + if len(errors) > 0 { + var messages []string + for _, err := range errors { + messages = append(messages, err.Message) + } + t.Fatalf("Expected no errors but found %d in %s: %v", len(errors), fileName, messages) + } + } +} + +// VerifyErrorExistsAtRange verifies that an error with the given code exists at the given range. +func (f *FourslashTest) VerifyErrorExistsAtRange(t *testing.T, rangeMarker *RangeMarker, code int, message string) { + diagnostics := f.getDiagnostics(t, rangeMarker.FileName()) + for _, diag := range diagnostics { + if diag.Code != nil && diag.Code.Integer != nil && int(*diag.Code.Integer) == code { + // Check if the range matches + if diag.Range.Start.Line == rangeMarker.LSRange.Start.Line && + diag.Range.Start.Character == rangeMarker.LSRange.Start.Character && + diag.Range.End.Line == rangeMarker.LSRange.End.Line && + diag.Range.End.Character == rangeMarker.LSRange.End.Character { + // If message is provided, verify it matches + if message != "" && diag.Message != message { + t.Fatalf("Error at range has code %d but message mismatch. Expected: %q, Got: %q", code, message, diag.Message) + } + return + } + } + } + t.Fatalf("Expected error with code %d at range %v but it was not found", code, rangeMarker.LSRange) +} + +// VerifyCurrentLineContentIs verifies that the current line content matches the expected text. +func (f *FourslashTest) VerifyCurrentLineContentIs(t *testing.T, expectedText string) { + script := f.getScriptInfo(f.activeFilename) + lines := strings.Split(script.content, "\n") + lineNum := int(f.currentCaretPosition.Line) + if lineNum >= len(lines) { + t.Fatalf("Current line %d is out of range (file has %d lines)", lineNum, len(lines)) + } + actualLine := lines[lineNum] + // Handle \r if present + actualLine = strings.TrimSuffix(actualLine, "\r") + if actualLine != expectedText { + t.Fatalf("Current line content mismatch.\nExpected: %q\nActual: %q", expectedText, actualLine) + } +} + +// VerifyCurrentFileContentIs verifies that the current file content matches the expected text. +func (f *FourslashTest) VerifyCurrentFileContentIs(t *testing.T, expectedText string) { + script := f.getScriptInfo(f.activeFilename) + if script.content != expectedText { + t.Fatalf("Current file content mismatch.\nExpected: %q\nActual: %q", expectedText, script.content) + } +} + +// VerifyErrorExistsBetweenMarkers verifies that an error exists between the two markers. +func (f *FourslashTest) VerifyErrorExistsBetweenMarkers(t *testing.T, startMarkerName string, endMarkerName string) { + startMarker, ok := f.testData.MarkerPositions[startMarkerName] + if !ok { + t.Fatalf("Start marker '%s' not found", startMarkerName) + } + endMarker, ok := f.testData.MarkerPositions[endMarkerName] + if !ok { + t.Fatalf("End marker '%s' not found", endMarkerName) + } + if startMarker.FileName() != endMarker.FileName() { + t.Fatalf("Markers '%s' and '%s' are in different files", startMarkerName, endMarkerName) + } + + diagnostics := f.getDiagnostics(t, startMarker.FileName()) + startPos := startMarker.Position + endPos := endMarker.Position + + for _, diag := range diagnostics { + if !isSuggestionDiagnostic(diag) { + diagStart := int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(startMarker.FileName()), diag.Range.Start)) + diagEnd := int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(startMarker.FileName()), diag.Range.End)) + if diagStart >= startPos && diagEnd <= endPos { + return // Found an error in the range + } + } + } + t.Fatalf("Expected error between markers '%s' and '%s' but none was found", startMarkerName, endMarkerName) +} + +// VerifyErrorExistsAfterMarker verifies that an error exists after the given marker. +func (f *FourslashTest) VerifyErrorExistsAfterMarker(t *testing.T, markerName string) { + var fileName string + var markerPos int + + if markerName == "" { + // Use current position + fileName = f.activeFilename + markerPos = int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(f.activeFilename), f.currentCaretPosition)) + } else { + marker, ok := f.testData.MarkerPositions[markerName] + if !ok { + t.Fatalf("Marker '%s' not found", markerName) + } + fileName = marker.FileName() + markerPos = marker.Position + } + + diagnostics := f.getDiagnostics(t, fileName) + + for _, diag := range diagnostics { + if !isSuggestionDiagnostic(diag) { + diagStart := int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(fileName), diag.Range.Start)) + if diagStart >= markerPos { + return // Found an error after the marker + } + } + } + t.Fatalf("Expected error after marker '%s' but none was found", markerName) +} + +// VerifyErrorExistsBeforeMarker verifies that an error exists before the given marker. +func (f *FourslashTest) VerifyErrorExistsBeforeMarker(t *testing.T, markerName string) { + var fileName string + var markerPos int + + if markerName == "" { + // Use current position + fileName = f.activeFilename + markerPos = int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(f.activeFilename), f.currentCaretPosition)) + } else { + marker, ok := f.testData.MarkerPositions[markerName] + if !ok { + t.Fatalf("Marker '%s' not found", markerName) + } + fileName = marker.FileName() + markerPos = marker.Position + } + + diagnostics := f.getDiagnostics(t, fileName) + + for _, diag := range diagnostics { + if !isSuggestionDiagnostic(diag) { + diagEnd := int(f.converters.LineAndCharacterToPosition(f.getScriptInfo(fileName), diag.Range.End)) + if diagEnd <= markerPos { + return // Found an error before the marker + } + } + } + t.Fatalf("Expected error before marker '%s' but none was found", markerName) +} diff --git a/internal/fourslash/tests/gen/addDeclareToFunction_test.go b/internal/fourslash/tests/gen/addDeclareToFunction_test.go new file mode 100644 index 0000000000..23a2973d07 --- /dev/null +++ b/internal/fourslash/tests/gen/addDeclareToFunction_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddDeclareToFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function parseInt(s/*2*/:string):number;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.DeleteAtCaret(t, 7) + f.GoToMarker(t, "1") + f.Insert(t, "declare ") +} diff --git a/internal/fourslash/tests/gen/addFunctionInDuplicatedConstructorClassBody_test.go b/internal/fourslash/tests/gen/addFunctionInDuplicatedConstructorClassBody_test.go new file mode 100644 index 0000000000..a392447038 --- /dev/null +++ b/internal/fourslash/tests/gen/addFunctionInDuplicatedConstructorClassBody_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddFunctionInDuplicatedConstructorClassBody(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + constructor() { } + constructor() { } + /**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "fn() { }") + f.VerifyNumberOfErrorsInCurrentFile(t, 2) +} diff --git a/internal/fourslash/tests/gen/allowLateBoundSymbolsOverwriteEarlyBoundSymbols_test.go b/internal/fourslash/tests/gen/allowLateBoundSymbolsOverwriteEarlyBoundSymbols_test.go new file mode 100644 index 0000000000..2277aebaac --- /dev/null +++ b/internal/fourslash/tests/gen/allowLateBoundSymbolsOverwriteEarlyBoundSymbols_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAllowLateBoundSymbolsOverwriteEarlyBoundSymbols(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export {}; +const prop = "abc"; +function foo(): void {}; +foo.abc = 10; +foo[prop] = 10; +interface T0 { + [prop]: number; + abc: number; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/ambientVariablesWithSameName_test.go b/internal/fourslash/tests/gen/ambientVariablesWithSameName_test.go new file mode 100644 index 0000000000..3eaa6e4619 --- /dev/null +++ b/internal/fourslash/tests/gen/ambientVariablesWithSameName_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAmbientVariablesWithSameName(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare module M { + export var x: string; +} +declare var x: number;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.InsertLine(t, "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/arityErrorAfterStringCompletions_test.go b/internal/fourslash/tests/gen/arityErrorAfterStringCompletions_test.go new file mode 100644 index 0000000000..9557b95d17 --- /dev/null +++ b/internal/fourslash/tests/gen/arityErrorAfterStringCompletions_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestArityErrorAfterStringCompletions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +interface Events { + click: any; + drag: any; +} + +declare function addListener(type: K, listener: (ev: Events[K]) => any): void; + +/*1*/addListener/*2*/("/*3*/")` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, []string{"3"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "click", + "drag", + }, + }, + }) + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/asConstRefsNoErrors1_test.go b/internal/fourslash/tests/gen/asConstRefsNoErrors1_test.go new file mode 100644 index 0000000000..7389da0b10 --- /dev/null +++ b/internal/fourslash/tests/gen/asConstRefsNoErrors1_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAsConstRefsNoErrors1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Tex { + type = 'Text' as /**/const; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineGoToDefinition(t, true, "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/asConstRefsNoErrors2_test.go b/internal/fourslash/tests/gen/asConstRefsNoErrors2_test.go new file mode 100644 index 0000000000..2183382632 --- /dev/null +++ b/internal/fourslash/tests/gen/asConstRefsNoErrors2_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAsConstRefsNoErrors2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Tex { + type = 'Text'; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineGoToDefinition(t, true, "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/asConstRefsNoErrors3_test.go b/internal/fourslash/tests/gen/asConstRefsNoErrors3_test.go new file mode 100644 index 0000000000..b786defcfc --- /dev/null +++ b/internal/fourslash/tests/gen/asConstRefsNoErrors3_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAsConstRefsNoErrors3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: file.js +class Tex { + type = (/** @type {/**/const} */'Text'); +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineGoToDefinition(t, true, "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go new file mode 100644 index 0000000000..f019b9037b --- /dev/null +++ b/internal/fourslash/tests/gen/autoFormattingOnPasting_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoFormattingOnPasting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module TestModule { +/**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Paste(t, " class TestClass{\nprivate foo;\npublic testMethod( )\n{}\n}") + f.VerifyCurrentFileContentIs(t, "module TestModule {\n class TestClass {\n private foo;\n public testMethod() { }\n }\n}") +} diff --git a/internal/fourslash/tests/gen/automaticConstructorToggling_test.go b/internal/fourslash/tests/gen/automaticConstructorToggling_test.go new file mode 100644 index 0000000000..85da88df22 --- /dev/null +++ b/internal/fourslash/tests/gen/automaticConstructorToggling_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutomaticConstructorToggling(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { } +class B {/*B*/ } +class C { /*C*/constructor(val: T) { } } +class D { constructor(/*D*/val: T) { } } + +new /*Asig*/A(); +new /*Bsig*/B(""); +new /*Csig*/C(""); +new /*Dsig*/D();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "B") + f.Insert(t, "constructor(val: T) { }") + f.VerifyQuickInfoAt(t, "Asig", "constructor A(): A", "") + f.VerifyQuickInfoAt(t, "Bsig", "constructor B(val: string): B", "") + f.VerifyQuickInfoAt(t, "Csig", "constructor C(val: string): C", "") + f.VerifyQuickInfoAt(t, "Dsig", "constructor D(val: string): D", "") + f.GoToMarker(t, "C") + f.DeleteAtCaret(t, 23) + f.VerifyQuickInfoAt(t, "Asig", "constructor A(): A", "") + f.VerifyQuickInfoAt(t, "Bsig", "constructor B(val: string): B", "") + f.VerifyQuickInfoAt(t, "Csig", "constructor C(): C", "") + f.VerifyQuickInfoAt(t, "Dsig", "constructor D(val: string): D", "") + f.GoToMarker(t, "D") + f.DeleteAtCaret(t, 6) + f.VerifyQuickInfoAt(t, "Asig", "constructor A(): A", "") + f.VerifyQuickInfoAt(t, "Bsig", "constructor B(val: string): B", "") + f.VerifyQuickInfoAt(t, "Csig", "constructor C(): C", "") + f.VerifyQuickInfoAt(t, "Dsig", "constructor D(): D", "") +} diff --git a/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go new file mode 100644 index 0000000000..224810322e --- /dev/null +++ b/internal/fourslash/tests/gen/chainedFatArrowFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestChainedFatArrowFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var fn = () => () => null/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "var fn = () => () => null;") +} diff --git a/internal/fourslash/tests/gen/cloduleAsBaseClass2_test.go b/internal/fourslash/tests/gen/cloduleAsBaseClass2_test.go new file mode 100644 index 0000000000..53e896dd98 --- /dev/null +++ b/internal/fourslash/tests/gen/cloduleAsBaseClass2_test.go @@ -0,0 +1,92 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCloduleAsBaseClass2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: cloduleAsBaseClass2_0.ts +class A { + constructor(x: number) { } + foo() { } + static bar() { } +} + +module A { + export var x = 1; + export function baz() { } +} + +export = A; +// @Filename: cloduleAsBaseClass2_1.ts +import B = require('./cloduleAsBaseClass2_0'); +class D extends B { + constructor() { + super(1); + } + foo2() { } + static bar2() { } +} + +var d: D; +d./*1*/ +D./*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "foo", + "foo2", + }, + }, + }) + f.Insert(t, "foo()") + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "bar", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + &lsproto.CompletionItem{ + Label: "bar2", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + &lsproto.CompletionItem{ + Label: "baz", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "x", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + }, + Excludes: []string{ + "foo", + "foo2", + }, + }, + }) + f.Insert(t, "bar()") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/cloduleAsBaseClass_test.go b/internal/fourslash/tests/gen/cloduleAsBaseClass_test.go new file mode 100644 index 0000000000..0ea8d9ad0d --- /dev/null +++ b/internal/fourslash/tests/gen/cloduleAsBaseClass_test.go @@ -0,0 +1,89 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCloduleAsBaseClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { + constructor(x: number) { } + foo() { } + static bar() { } +} + +module A { + export var x = 1; + export function baz() { } +} + +class D extends A { + constructor() { + super(1); + } + foo2() { } + static bar2() { } +} + +var d: D; +d./*1*/ +D./*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "foo", + "foo2", + }, + }, + }) + f.Insert(t, "foo()") + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: CompletionFunctionMembersPlus( + []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "bar", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + &lsproto.CompletionItem{ + Label: "bar2", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + &lsproto.CompletionItem{ + Label: "baz", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "prototype", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "x", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + }), + }, + }) + f.Insert(t, "bar()") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/cloduleTypeOf1_test.go b/internal/fourslash/tests/gen/cloduleTypeOf1_test.go new file mode 100644 index 0000000000..de4926aee0 --- /dev/null +++ b/internal/fourslash/tests/gen/cloduleTypeOf1_test.go @@ -0,0 +1,80 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCloduleTypeOf1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + static foo(x: number) { } + x: T; +} + +module C { + export function f(x: typeof C) { + x./*1*/ + var /*3*/r = new /*2*/x(); + var /*5*/r2 = r./*4*/ + return typeof r; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "f", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "foo", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + }, + }, + }) + f.Insert(t, "foo(1);") + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "x", + }, + }, + }) + f.VerifyQuickInfoAt(t, "3", "(local var) r: C", "") + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "x", + }, + }, + }) + f.Insert(t, "x;") + f.VerifyQuickInfoAt(t, "5", "(local var) r2: number", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/codeFixCannotFindModule_suggestion_falsePositive_test.go b/internal/fourslash/tests/gen/codeFixCannotFindModule_suggestion_falsePositive_test.go new file mode 100644 index 0000000000..3ad280f3b7 --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixCannotFindModule_suggestion_falsePositive_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixCannotFindModule_suggestion_falsePositive(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @moduleResolution: bundler +// @resolveJsonModule: true +// @strict: true +// @Filename: /node_modules/foo/bar.json +{ "a": 0 } +// @Filename: /a.ts +import abs = require([|"foo/bar.json"|]); +abs;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToFile(t, "/a.ts") + f.VerifySuggestionDiagnostics(t, nil) +} diff --git a/internal/fourslash/tests/gen/codeFixSpellingJs3_test.go b/internal/fourslash/tests/gen/codeFixSpellingJs3_test.go new file mode 100644 index 0000000000..55230d55e3 --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixSpellingJs3_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixSpellingJs3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowjs: true +// @noEmit: true +// @filename: a.js +class Classe { + non = 'oui' + methode() { + // no error on 'this' references + return this.none + } +} +class Derivee extends Classe { + methode() { + // no error on 'super' references + return super.none + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/codeFixSpellingJs5_test.go b/internal/fourslash/tests/gen/codeFixSpellingJs5_test.go new file mode 100644 index 0000000000..bc93aed32d --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixSpellingJs5_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixSpellingJs5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowjs: true +// @noEmit: true +// @filename: a.js +var other = { + puuce: 4 +} +var Jimmy = 1 +var John = 2 +// @filename: b.js +other.puuuce // OK, from another file +new Date().getGMTDate() // OK, from another file +window.argle // OK, from globalThis +self.blargle // OK, from globalThis + +// No suggestions for globals from other files +const atoc = setIntegral(() => console.log('ok'), 500) +AudioBuffin // etc +Jimmy +Jon` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/codeFixSpellingJs6_test.go b/internal/fourslash/tests/gen/codeFixSpellingJs6_test.go new file mode 100644 index 0000000000..eb086ff533 --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixSpellingJs6_test.go @@ -0,0 +1,68 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixSpellingJs6(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowjs: true +// @checkjs: false +// @noEmit: true +// @filename: spellingUncheckedJS.js +export var inModule = 1 +inmodule.toFixed() + +function f() { + var locals = 2 + true + locale.toFixed() +} +class Classe { + non = 'oui' + methode() { + // no error on 'this' references + return this.none + } +} +class Derivee extends Classe { + methode() { + // no error on 'super' references + return super.none + } +} + + +var object = { + spaaace: 3 +} +object.spaaaace // error on read +object.spaace = 12 // error on write +object.fresh = 12 // OK +other.puuuce // OK, from another file +new Date().getGMTDate() // OK, from another file + +// No suggestions for globals from other files +const atoc = setIntegral(() => console.log('ok'), 500) +AudioBuffin // etc +Jimmy +Jon +window.argle +self.blargle +// @filename: other.js +var Jimmy = 1 +var John = 2 +Jon // error, it's from the same file +var other = { + puuce: 4 +} +window.argle +self.blargle` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/codeFixSpellingJs7_test.go b/internal/fourslash/tests/gen/codeFixSpellingJs7_test.go new file mode 100644 index 0000000000..d8c78fcbf0 --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixSpellingJs7_test.go @@ -0,0 +1,69 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixSpellingJs7(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowjs: true +// @noEmit: true +// @filename: spellingUncheckedJS.js +// @ts-nocheck +export var inModule = 1 +inmodule.toFixed() + +function f() { + var locals = 2 + true + locale.toFixed() +} +class Classe { + non = 'oui' + methode() { + // no error on 'this' references + return this.none + } +} +class Derivee extends Classe { + methode() { + // no error on 'super' references + return super.none + } +} + + +var object = { + spaaace: 3 +} +object.spaaaace // error on read +object.spaace = 12 // error on write +object.fresh = 12 // OK +other.puuuce // OK, from another file +new Date().getGMTDate() // OK, from another file + +// No suggestions for globals from other files +const atoc = setIntegral(() => console.log('ok'), 500) +AudioBuffin // etc +Jimmy +Jon +window.argle +self.blargle +// @filename: other.js +// @ts-nocheck +var Jimmy = 1 +var John = 2 +Jon // error, it's from the same file +var other = { + puuce: 4 +} +window.argle +self.blargle` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/codeFixSpellingJs8_test.go b/internal/fourslash/tests/gen/codeFixSpellingJs8_test.go new file mode 100644 index 0000000000..4a3b192527 --- /dev/null +++ b/internal/fourslash/tests/gen/codeFixSpellingJs8_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCodeFixSpellingJs8(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowjs: true +// @noEmit: true +// @filename: a.js +var locals = {} +// @ts-expect-error +Object.keys(locale)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/completionBeforeSemanticDiagnosticsInArrowFunction1_test.go b/internal/fourslash/tests/gen/completionBeforeSemanticDiagnosticsInArrowFunction1_test.go new file mode 100644 index 0000000000..3e7aeeabc2 --- /dev/null +++ b/internal/fourslash/tests/gen/completionBeforeSemanticDiagnosticsInArrowFunction1_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionBeforeSemanticDiagnosticsInArrowFunction1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var f4 = (x: T/**/ ) => { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Backspace(t, 1) + f.Insert(t, "A") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "T", + Detail: PtrTo("(type parameter) T in (x: A): void"), + }, + }, + }, + }) + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/completionListInImportClause04_test.go b/internal/fourslash/tests/gen/completionListInImportClause04_test.go new file mode 100644 index 0000000000..63af454092 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInImportClause04_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInImportClause04(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.d.ts + declare class Foo { + static prop1(x: number): number; + static prop1(x: string): string; + static prop2(x: boolean): boolean; + } + export = Foo; /*2*/ +// @Filename: app.ts +import {/*1*/} from './foo';` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{ + "prototype", + "prop1", + "prop2", + &lsproto.CompletionItem{ + Label: "type", + SortText: PtrTo(string(ls.SortTextGlobalsOrKeywords)), + }, + }, + }, + }) + f.VerifyNoErrors(t) + f.GoToMarker(t, "2") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/consistentContextualTypeErrorsAfterEdits_test.go b/internal/fourslash/tests/gen/consistentContextualTypeErrorsAfterEdits_test.go new file mode 100644 index 0000000000..b044d73009 --- /dev/null +++ b/internal/fourslash/tests/gen/consistentContextualTypeErrorsAfterEdits_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestConsistentContextualTypeErrorsAfterEdits(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { + foo: string; +} +class C { + foo: string; +} +var xs /*1*/ = [(x: A) => { return x.foo; }, (x: C) => { return x.foo; }]; +xs.forEach(y => y(new /*2*/A()));` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "1") + f.Insert(t, ": {}[]") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "2") + f.DeleteAtCaret(t, 1) + f.Insert(t, "C") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/constructorBraceFormatting_test.go b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go new file mode 100644 index 0000000000..7a7a087065 --- /dev/null +++ b/internal/fourslash/tests/gen/constructorBraceFormatting_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestConstructorBraceFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X { + constructor () {}/*target*/ + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "target") + f.VerifyCurrentLineContentIs(t, " constructor() { }") +} diff --git a/internal/fourslash/tests/gen/contextualTypingOfGenericCallSignatures2_test.go b/internal/fourslash/tests/gen/contextualTypingOfGenericCallSignatures2_test.go new file mode 100644 index 0000000000..e0a66783ea --- /dev/null +++ b/internal/fourslash/tests/gen/contextualTypingOfGenericCallSignatures2_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestContextualTypingOfGenericCallSignatures2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + (x: T): void +} +function f6(x: (p: T) => void) { } +// x should not be contextually typed so this should be an error +f6(/**/x => x())` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "(parameter) x: T extends I", "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/deduplicateDuplicateMergedBindCheckErrors_test.go b/internal/fourslash/tests/gen/deduplicateDuplicateMergedBindCheckErrors_test.go new file mode 100644 index 0000000000..309a659f0c --- /dev/null +++ b/internal/fourslash/tests/gen/deduplicateDuplicateMergedBindCheckErrors_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDeduplicateDuplicateMergedBindCheckErrors(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X { + foo() { + return 1; + } + get foo() { + return 1; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 2) +} diff --git a/internal/fourslash/tests/gen/deleteClassWithEnumPresent_test.go b/internal/fourslash/tests/gen/deleteClassWithEnumPresent_test.go new file mode 100644 index 0000000000..f673040744 --- /dev/null +++ b/internal/fourslash/tests/gen/deleteClassWithEnumPresent_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDeleteClassWithEnumPresent(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum Foo { a, b, c } +/**/class Bar { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 13) + f.VerifyBaselineDocumentSymbol(t) +} diff --git a/internal/fourslash/tests/gen/deleteExtensionInReopenedInterface_test.go b/internal/fourslash/tests/gen/deleteExtensionInReopenedInterface_test.go new file mode 100644 index 0000000000..033b0de79c --- /dev/null +++ b/internal/fourslash/tests/gen/deleteExtensionInReopenedInterface_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDeleteExtensionInReopenedInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { a: number; } +interface B { b: number; } + +interface I /*del*/extends A { } +interface I extends B { } + +var i: I; +class C /*delImplements*/implements A { } +var c: C; +c.a;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "del") + f.DeleteAtCaret(t, 9) + f.GoToEOF(t) + f.Insert(t, "var a = i.a;") + f.GoToMarker(t, "delImplements") + f.DeleteAtCaret(t, 12) + f.GoToMarker(t, "del") + f.Insert(t, "extends A") +} diff --git a/internal/fourslash/tests/gen/deleteModifierBeforeVarStatement1_test.go b/internal/fourslash/tests/gen/deleteModifierBeforeVarStatement1_test.go new file mode 100644 index 0000000000..9e46ad9707 --- /dev/null +++ b/internal/fourslash/tests/gen/deleteModifierBeforeVarStatement1_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDeleteModifierBeforeVarStatement1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` + +///////////////////////////// +/// Windows Script Host APIS +///////////////////////////// + +declare var ActiveXObject: { new (s: string): any; }; + +interface ITextWriter { + WriteLine(s): void; +} + +declare var WScript: { + Echo(s): void; + StdErr: ITextWriter; + Arguments: { length: number; Item(): string; }; + ScriptFullName: string; + Quit(): number; +} +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFileNumber(t, 0) + f.GoToPosition(t, 0) + f.DeleteAtCaret(t, 100) + f.GoToPosition(t, 198) + f.DeleteAtCaret(t, 16) + f.GoToPosition(t, 198) + f.Insert(t, "Item(): string; ") +} diff --git a/internal/fourslash/tests/gen/deleteTypeParameter_test.go b/internal/fourslash/tests/gen/deleteTypeParameter_test.go new file mode 100644 index 0000000000..34ffd07608 --- /dev/null +++ b/internal/fourslash/tests/gen/deleteTypeParameter_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDeleteTypeParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Query { + groupBy(): Query; +} +interface Query2 { + groupBy(): Query2>; +} +var q1: Query; +var q2: Query2; +q1 = q2;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 1) +} diff --git a/internal/fourslash/tests/gen/derivedTypeIndexerWithGenericConstraints_test.go b/internal/fourslash/tests/gen/derivedTypeIndexerWithGenericConstraints_test.go new file mode 100644 index 0000000000..19d185c2cc --- /dev/null +++ b/internal/fourslash/tests/gen/derivedTypeIndexerWithGenericConstraints_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDerivedTypeIndexerWithGenericConstraints(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class CollectionItem { + x: number; +} +class Entity extends CollectionItem { + y: number; +} +class BaseCollection { + _itemsByKey: { [key: string]: TItem; }; +} +class DbSet extends BaseCollection { // error + _itemsByKey: { [key: string]: TEntity; } = {}; +} +var a: BaseCollection; +var /**/r = a._itemsByKey['x']; // should just say CollectionItem not TItem extends CollectionItem +var result = r.x; +a = new DbSet(); +var r2 = a._itemsByKey['x']; +var result2 = r2.x;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "var r: CollectionItem", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/duplicatePackageServices_test.go b/internal/fourslash/tests/gen/duplicatePackageServices_test.go new file mode 100644 index 0000000000..a6bb545b38 --- /dev/null +++ b/internal/fourslash/tests/gen/duplicatePackageServices_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDuplicatePackageServices(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noImplicitReferences: true +// @Filename: /node_modules/a/index.d.ts +import [|X/*useAX*/|] from "x"; +export function a(x: X): void; +// @Filename: /node_modules/a/node_modules/x/index.d.ts +export default class /*defAX*/X { + private x: number; +} +// @Filename: /node_modules/a/node_modules/x/package.json +{ "name": "x", "version": "1.2.3" } +// @Filename: /node_modules/b/index.d.ts +import [|X/*useBX*/|] from "x"; +export const b: X; +// @Filename: /node_modules/b/node_modules/x/index.d.ts +export default class /*defBX*/X { + private x: number; +} +// @Filename: /node_modules/b/node_modules/x/package.json +{ "name": "x", "version": "1.2.3" } +// @Filename: /src/a.ts +import { a } from "a"; +import { b } from "b"; +a(/*error*/b);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "/src/a.ts") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.VerifyBaselineFindAllReferences(t, "useAX", "defAX", "useBX") + f.VerifyBaselineGoToDefinition(t, true, "useAX", "useBX") +} diff --git a/internal/fourslash/tests/gen/editLambdaArgToTypeParameter1_test.go b/internal/fourslash/tests/gen/editLambdaArgToTypeParameter1_test.go new file mode 100644 index 0000000000..f56da9ff52 --- /dev/null +++ b/internal/fourslash/tests/gen/editLambdaArgToTypeParameter1_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestEditLambdaArgToTypeParameter1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + foo(x: T) { + return (a: number/*1*/) => x; + } +} +/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Backspace(t, 6) + f.Insert(t, "T") + f.VerifyNoErrors(t) + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/enumUpdate1_test.go b/internal/fourslash/tests/gen/enumUpdate1_test.go new file mode 100644 index 0000000000..7c067507ab --- /dev/null +++ b/internal/fourslash/tests/gen/enumUpdate1_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestEnumUpdate1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export enum E { + A = 1, + B = 2, + C = 3, + /*1*/ + } +} +module M { + function foo(): M.E { + return M.E.A; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.Insert(t, "D = C << 1,") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/errorConsistency_test.go b/internal/fourslash/tests/gen/errorConsistency_test.go new file mode 100644 index 0000000000..778f69bed1 --- /dev/null +++ b/internal/fourslash/tests/gen/errorConsistency_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestErrorConsistency(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Int { +val(f: (t: T) => U): Int; +} +declare var v1: Int; +var /*1*/v2/*2*/: Int = v1;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.Backspace(t, 1) + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/errorInIncompleteMethodInObjectLiteral_test.go b/internal/fourslash/tests/gen/errorInIncompleteMethodInObjectLiteral_test.go new file mode 100644 index 0000000000..7c9701ac2a --- /dev/null +++ b/internal/fourslash/tests/gen/errorInIncompleteMethodInObjectLiteral_test.go @@ -0,0 +1,18 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestErrorInIncompleteMethodInObjectLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: { f(): string } = { f( }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/errorsAfterResolvingVariableDeclOfMergedVariableAndClassDecl_test.go b/internal/fourslash/tests/gen/errorsAfterResolvingVariableDeclOfMergedVariableAndClassDecl_test.go new file mode 100644 index 0000000000..722390f434 --- /dev/null +++ b/internal/fourslash/tests/gen/errorsAfterResolvingVariableDeclOfMergedVariableAndClassDecl_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestErrorsAfterResolvingVariableDeclOfMergedVariableAndClassDecl(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export class C { + foo() { } + } + export module C { + export var /*1*/C = M.C; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.Backspace(t, 1) + f.Insert(t, " ") + f.VerifyQuickInfoIs(t, "var M.C.C: typeof M.C", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/exportEqualTypes_test.go b/internal/fourslash/tests/gen/exportEqualTypes_test.go new file mode 100644 index 0000000000..2f7123268c --- /dev/null +++ b/internal/fourslash/tests/gen/exportEqualTypes_test.go @@ -0,0 +1,46 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExportEqualTypes(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: exportEqualTypes_file0.ts +interface x { + (): Date; + foo: string; +} +export = x; +// @Filename: exportEqualTypes_file1.ts +/// +import test = require('./exportEqualTypes_file0'); +var t: /*1*/test; // var 't' should be of type 'test' +var /*2*/r1 = t(); // Should return a Date +var /*3*/r2 = t./*4*/foo; // t should have 'foo' in dropdown list and be of type 'string'` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "(alias) interface test\nimport test = require('./exportEqualTypes_file0')", "") + f.VerifyQuickInfoAt(t, "2", "var r1: Date", "") + f.VerifyQuickInfoAt(t, "3", "var r2: string", "") + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: CompletionFunctionMembersWithPrototypePlus( + []fourslash.CompletionsExpectedItem{ + "foo", + }), + }, + }) + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/extendInterfaceOverloadedMethod_test.go b/internal/fourslash/tests/gen/extendInterfaceOverloadedMethod_test.go new file mode 100644 index 0000000000..fae5511c10 --- /dev/null +++ b/internal/fourslash/tests/gen/extendInterfaceOverloadedMethod_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExtendInterfaceOverloadedMethod(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + foo(a: T): B; + foo(): void ; + foo2(): B; +} +interface B extends A { + bar(): void ; +} +var b: B; +var /**/x = b.foo2().foo(5).foo(); // 'x' is of type 'void'` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "var x: void", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/extendsTArray_test.go b/internal/fourslash/tests/gen/extendsTArray_test.go new file mode 100644 index 0000000000..aaa94531a0 --- /dev/null +++ b/internal/fourslash/tests/gen/extendsTArray_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExtendsTArray(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I1 { + (a: T): T; +} +interface I2 extends I1 { + b: T; +} +var x: I2; +var /**/y = x(undefined); // Typeof y should be Date[] +y.length;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "var y: Date[]", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/externalModuleIntellisense_test.go b/internal/fourslash/tests/gen/externalModuleIntellisense_test.go new file mode 100644 index 0000000000..f8a8ffb480 --- /dev/null +++ b/internal/fourslash/tests/gen/externalModuleIntellisense_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExternalModuleIntellisense(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: externalModuleIntellisense_file0.ts +export = express; +function express(): express.ExpressServer; +module express { + export interface ExpressServer { + enable(name: string): ExpressServer; + post(path: RegExp, handler: (req: Function) => void): void; + } + export class ExpressServerRequest { + } +} +// @Filename: externalModuleIntellisense_file1.ts +/// +import express = require('./externalModuleIntellisense_file0'); +var x = express();/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToEOF(t) + f.Insert(t, "x.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "enable", + "post", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/failureToImplementClass_test.go b/internal/fourslash/tests/gen/failureToImplementClass_test.go new file mode 100644 index 0000000000..11dc3b314a --- /dev/null +++ b/internal/fourslash/tests/gen/failureToImplementClass_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFailureToImplementClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface IExec { + exec: (filename: string, cmdLine: string) => boolean; +} +class /*1*/NodeExec/*2*/ implements IExec { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/findAllRefsExportAsNamespace_test.go b/internal/fourslash/tests/gen/findAllRefsExportAsNamespace_test.go new file mode 100644 index 0000000000..fa0a574ce6 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsExportAsNamespace_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsExportAsNamespace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /node_modules/a/index.d.ts +export function /*0*/f(): void; +export as namespace A; +// @Filename: /b.ts +import { /*1*/f } from "a"; +// @Filename: /c.ts +A./*2*/f();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport08_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport08_test.go new file mode 100644 index 0000000000..9f553b7540 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport08_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsForDefaultExport08(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export default class DefaultExportedClass { +} + +var x: DefaultExportedClass; + +var y = new DefaultExportedClass; + +namespace /*1*/DefaultExportedClass { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports_test.go new file mode 100644 index 0000000000..4d7b6cd205 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowSyntheticDefaultImports: true +// @Filename: /export.ts +const /*0*/foo = 1; +export = /*1*/foo; +// @Filename: /re-export.ts +export { /*2*/default } from "./export"; +// @Filename: /re-export-dep.ts +import /*3*/fooDefault from "./re-export";` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForModuleGlobal_test.go b/internal/fourslash/tests/gen/findAllRefsForModuleGlobal_test.go new file mode 100644 index 0000000000..c1d79581fa --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForModuleGlobal_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsForModuleGlobal(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /node_modules/foo/index.d.ts +export const x = 0; +// @Filename: /b.ts +/// +import { x } from "/*1*/foo"; +declare module "foo" {}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsGlobalModuleAugmentation_test.go b/internal/fourslash/tests/gen/findAllRefsGlobalModuleAugmentation_test.go new file mode 100644 index 0000000000..73b2b756d1 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsGlobalModuleAugmentation_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsGlobalModuleAugmentation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export {}; +declare global { + /*1*/function /*2*/f(): void; +} +// @Filename: /b.ts +/*3*/f();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportDefault_test.go b/internal/fourslash/tests/gen/findAllRefsImportDefault_test.go new file mode 100644 index 0000000000..f1cd6df7c7 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportDefault_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsImportDefault(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: f.ts +export { foo as default }; +function /*start*/foo(a: number, b: number) { + return a + b; +} +// @Filename: b.ts +import bar from "./f"; +bar(1, 2);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "start") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportEqualsJsonFile_test.go b/internal/fourslash/tests/gen/findAllRefsImportEqualsJsonFile_test.go new file mode 100644 index 0000000000..f8ea64d30b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportEqualsJsonFile_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsImportEqualsJsonFile(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @resolveJsonModule: true +// @Filename: /a.ts +import /*0*/j = require("/*1*/./j.json"); +/*2*/j; +// @Filename: /b.js +const /*3*/j = require("/*4*/./j.json"); +/*5*/j; +// @Filename: /j.json +/*6*/{ "x": 0 }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "0", "2", "1", "4", "3", "5", "6") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportNamed_test.go b/internal/fourslash/tests/gen/findAllRefsImportNamed_test.go new file mode 100644 index 0000000000..0ef83a6d1b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportNamed_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsImportNamed(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: f.ts +export { foo as foo } +function /*start*/foo(a: number, b: number) { } +// @Filename: b.ts +import x = require("./f"); +x.foo(1, 2);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "start") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportStarOfExportEquals_test.go b/internal/fourslash/tests/gen/findAllRefsImportStarOfExportEquals_test.go new file mode 100644 index 0000000000..61165f3f90 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportStarOfExportEquals_test.go @@ -0,0 +1,36 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsImportStarOfExportEquals(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowSyntheticDefaultimports: true +// @Filename: /node_modules/a/index.d.ts +[|declare function /*a0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}a|](): void;|] +[|declare namespace /*a1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}a|] { + export const x: number; +}|] +[|export = /*a2*/[|{| "contextRangeIndex": 4 |}a|];|] +// @Filename: /b.ts +[|import /*b0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}b|] from "a";|] +/*b1*/[|b|](); +[|b|].x; +// @Filename: /c.ts +[|import /*c0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 10 |}a|] from "a";|] +/*c1*/[|a|](); +/*c2*/[|a|].x;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "a0", "a1", "a2", "b0", "b1", "c0", "c1", "c2") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[3], f.Ranges()[5]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[7], f.Ranges()[8], f.Ranges()[9]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[11], f.Ranges()[12], f.Ranges()[13]) +} diff --git a/internal/fourslash/tests/gen/findAllRefsModuleAugmentation_test.go b/internal/fourslash/tests/gen/findAllRefsModuleAugmentation_test.go new file mode 100644 index 0000000000..5ee8ca52cc --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsModuleAugmentation_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsModuleAugmentation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /node_modules/foo/index.d.ts +/*1*/export type /*2*/T = number; +// @Filename: /a.ts +import * as foo from "foo"; +declare module "foo" { + export const x: /*3*/T; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOfConstructor2_test.go b/internal/fourslash/tests/gen/findAllRefsOfConstructor2_test.go new file mode 100644 index 0000000000..e61175f632 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOfConstructor2_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsOfConstructor2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { + /*a*/constructor(s: string) {} +} +class B extends A { + /*b*/constructor() { super(""); } +} +class C extends B { + /*c*/constructor() { + super(); + } +} +class D extends B { } +const a = new A("a"); +const b = new B(); +const c = new C(); +const d = new D();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "a", "b", "c") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOfConstructor_multipleFiles_test.go b/internal/fourslash/tests/gen/findAllRefsOfConstructor_multipleFiles_test.go new file mode 100644 index 0000000000..795602df47 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOfConstructor_multipleFiles_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsOfConstructor_multipleFiles(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: f.ts +class A { + /*aCtr*/constructor(s: string) {} +} +class B extends A { } +export { A, B }; +// @Filename: a.ts +import { A as A1 } from "./f"; +const a1 = new A1("a1"); +export default class extends A1 { } +export { B as B1 } from "./f"; +// @Filename: b.ts +import B, { B1 } from "./a"; +const d = new B("b"); +const d1 = new B1("b1");` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "aCtr") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOfConstructor_test.go b/internal/fourslash/tests/gen/findAllRefsOfConstructor_test.go new file mode 100644 index 0000000000..43407191ec --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOfConstructor_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsOfConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { + /*aCtr*/constructor(s: string) {} +} +class B extends A { } +class C extends B { + /*cCtr*/constructor() { + super(""); + } +} +class D extends B { } +class E implements A { } +const a = new A("a"); +const b = new B("b"); +const c = new C(); +const d = new D("d"); +const e = new E();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "aCtr", "cCtr") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPrefixSuffixPreference_test.go b/internal/fourslash/tests/gen/findAllRefsPrefixSuffixPreference_test.go new file mode 100644 index 0000000000..c41396805e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPrefixSuffixPreference_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls/lsutil" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsPrefixSuffixPreference(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /file1.ts +declare function log(s: string | number): void; +[|const /*q0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}q|] = 1;|] +[|export { /*q1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}q|] };|] +const x = { + [|/*z0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}z|]: 'value'|] +} +[|const { /*z1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}z|] } = x;|] +log(/*z2*/[|z|]); +// @Filename: /file2.ts +declare function log(s: string | number): void; +[|import { /*q2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 9 |}q|] } from "./file1";|] +log(/*q3*/[|q|] + 1);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "q0", "q1", "q2", "q3", "z0", "z1", "z2") + f.VerifyBaselineRename(t, &lsutil.UserPreferences{UseAliasesForRename: core.TSTrue}, f.Ranges()[1], f.Ranges()[3], f.Ranges()[10], f.Ranges()[11]) + f.VerifyBaselineRename(t, &lsutil.UserPreferences{UseAliasesForRename: core.TSFalse}, f.Ranges()[1], f.Ranges()[3], f.Ranges()[10], f.Ranges()[11]) + f.VerifyBaselineRename(t, &lsutil.UserPreferences{UseAliasesForRename: core.TSTrue}, f.Ranges()[5], f.Ranges()[7], f.Ranges()[8]) + f.VerifyBaselineRename(t, &lsutil.UserPreferences{UseAliasesForRename: core.TSFalse}, f.Ranges()[5], f.Ranges()[7], f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExportLocal_test.go b/internal/fourslash/tests/gen/findAllRefsReExportLocal_test.go new file mode 100644 index 0000000000..d70aea6125 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExportLocal_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExportLocal(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +// @Filename: /a.ts +[|var /*ax0*/[|{| "isDefinition": true, "contextRangeIndex": 0 |}x|];|] +[|export { /*ax1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}x|] };|] +[|export { /*ax2*/[|{| "contextRangeIndex": 4 |}x|] as /*ay*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}y|] };|] +// @Filename: /b.ts +[|import { /*bx0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 7 |}x|], /*by0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 7 |}y|] } from "./a";|] +/*bx1*/[|x|]; /*by1*/[|y|];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "ax0", "ax1", "ax2", "bx0", "bx1", "ay", "by0", "by1") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[5]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[8], f.Ranges()[10]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[6]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[9], f.Ranges()[11]) +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExportRightNameWrongSymbol_test.go b/internal/fourslash/tests/gen/findAllRefsReExportRightNameWrongSymbol_test.go new file mode 100644 index 0000000000..120e75cfaf --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExportRightNameWrongSymbol_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExportRightNameWrongSymbol(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +[|export const /*a*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}x|] = 0;|] +// @Filename: /b.ts +[|export const /*b*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}x|] = 0;|] +//@Filename: /c.ts +[|export { /*cFromB*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}x|] } from "./b";|] +[|import { /*cFromA*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}x|] } from "./a";|] +/*cUse*/[|x|]; +// @Filename: /d.ts +[|import { /*d*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 9 |}x|] } from "./c";|]` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "a", "b", "cFromB", "cFromA", "cUse", "d") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[7], f.Ranges()[8]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[5]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[10]) +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExportStarAs_test.go b/internal/fourslash/tests/gen/findAllRefsReExportStarAs_test.go new file mode 100644 index 0000000000..7f9533377a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExportStarAs_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExportStarAs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /leafModule.ts +export const /*helloDef*/hello = () => 'Hello'; +// @Filename: /exporting.ts +export * as /*leafDef*/Leaf from './leafModule'; +// @Filename: /importing.ts + import { /*leafImportDef*/Leaf } from './exporting'; + /*leafUse*/[|Leaf|]./*helloUse*/[|hello|]()` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "helloDef", "helloUse", "leafDef", "leafImportDef", "leafUse") +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExportStar_test.go b/internal/fourslash/tests/gen/findAllRefsReExportStar_test.go new file mode 100644 index 0000000000..5ba4c63f0e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExportStar_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExportStar(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export function /*0*/foo(): void {} +// @Filename: /b.ts +export * from "./a"; +// @Filename: /c.ts +import { /*1*/foo } from "./b";` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExports2_test.go b/internal/fourslash/tests/gen/findAllRefsReExports2_test.go new file mode 100644 index 0000000000..d437f58e2a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExports2_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExports2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export function /*1*/foo(): void {} +// @Filename: /b.ts +import { foo as oof } from "./a";` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExportsUseInImportType_test.go b/internal/fourslash/tests/gen/findAllRefsReExportsUseInImportType_test.go new file mode 100644 index 0000000000..51e8f0c61d --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExportsUseInImportType_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls/lsutil" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsReExportsUseInImportType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /foo/types/types.ts +[|export type /*full0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}Full|] = { prop: string; };|] +// @Filename: /foo/types/index.ts +[|import * as /*foo0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}foo|] from './types';|] +[|export { /*foo1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}foo|] };|] +// @Filename: /app.ts +[|import { /*foo2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}foo|] } from './foo/types';|] +export type fullType = /*foo3*/[|foo|]./*full1*/[|Full|]; +type namespaceImport = typeof import('./foo/types'); +type fullType2 = import('./foo/types')./*foo4*/[|foo|]./*full2*/[|Full|];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "full0", "full1", "full2", "foo0", "foo1", "foo2", "foo3", "foo4") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[9], f.Ranges()[11]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[5], f.Ranges()[10]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[7], f.Ranges()[8]) + f.VerifyBaselineRename(t, &lsutil.UserPreferences{UseAliasesForRename: core.TSFalse}, f.Ranges()[7], f.Ranges()[8], f.Ranges()[10], f.Ranges()[3], f.Ranges()[5]) +} diff --git a/internal/fourslash/tests/gen/findAllRefsRenameImportWithSameName_test.go b/internal/fourslash/tests/gen/findAllRefsRenameImportWithSameName_test.go new file mode 100644 index 0000000000..5de0aceb20 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsRenameImportWithSameName_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsRenameImportWithSameName(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +[|export const /*0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}x|] = 0;|] +//@Filename: /b.ts +[|import { /*1*/[|{| "contextRangeIndex": 2 |}x|] as /*2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}x|] } from "./a";|] +/*3*/[|x|];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[3], f.Ranges()[4], f.Ranges()[5]) +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_js1_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js1_test.go new file mode 100644 index 0000000000..003017b3c8 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js1_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefs_importType_js1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: /a.js +module.exports = class /**/C {}; +module.exports.D = class D {}; +// @Filename: /b.js +/** @type {import("./a")} */ +const x = 0; +/** @type {import("./a").D} */ +const y = 0;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_js2_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js2_test.go new file mode 100644 index 0000000000..f5e6a62671 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js2_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefs_importType_js2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: /a.js +module.exports = class C {}; +module.exports./**/D = class D {}; +// @Filename: /b.js +/** @type {import("./a")} */ +const x = 0; +/** @type {import("./a").D} */ +const y = 0;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_js3_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js3_test.go new file mode 100644 index 0000000000..575e5911aa --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js3_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefs_importType_js3(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: /a.js +module.exports = class C {}; +module.exports.D = class /**/D {}; +// @Filename: /b.js +/** @type {import("./a")} */ +const x = 0; +/** @type {import("./a").D} */ +const y = 0;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_js_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js_test.go new file mode 100644 index 0000000000..ac5e5d4100 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefs_importType_js(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: /a.js +/**/module.exports = class C {}; +module.exports.D = class D {}; +// @Filename: /b.js +/** @type {import("./a")} */ +const x = 0; +/** @type {import("./a").D} */ +const y = 0;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/formatAfterWhitespace_test.go b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go new file mode 100644 index 0000000000..51216f75a1 --- /dev/null +++ b/internal/fourslash/tests/gen/formatAfterWhitespace_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAfterWhitespace(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo() +{ + var bar; + /*1*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.VerifyCurrentFileContentIs(t, "function foo()\n{\n var bar;\n\n\n}") +} diff --git a/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go new file mode 100644 index 0000000000..9256ee041c --- /dev/null +++ b/internal/fourslash/tests/gen/formatAnyTypeLiteral_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatAnyTypeLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo(x: { } /*objLit*/){ +/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "objLit") + f.VerifyCurrentLineContentIs(t, "function foo(x: {}) {") +} diff --git a/internal/fourslash/tests/gen/formatEmptyBlock_test.go b/internal/fourslash/tests/gen/formatEmptyBlock_test.go new file mode 100644 index 0000000000..1bca281322 --- /dev/null +++ b/internal/fourslash/tests/gen/formatEmptyBlock_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatEmptyBlock(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `{}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, "\n") + f.GoToBOF(t) + f.VerifyCurrentLineContentIs(t, "{ }") +} diff --git a/internal/fourslash/tests/gen/formatEmptyParamList_test.go b/internal/fourslash/tests/gen/formatEmptyParamList_test.go new file mode 100644 index 0000000000..268c96a601 --- /dev/null +++ b/internal/fourslash/tests/gen/formatEmptyParamList_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatEmptyParamList(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f( f: function){/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, "function f(f: function) { }") +} diff --git a/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go new file mode 100644 index 0000000000..170e9cb9c7 --- /dev/null +++ b/internal/fourslash/tests/gen/formatInTryCatchFinally_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatInTryCatchFinally(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try +{ + var x = 1/*1*/ +} +catch (e) +{ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " var x = 1;") +} diff --git a/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go new file mode 100644 index 0000000000..fc3e12d136 --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnEnterFunctionDeclaration_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnEnterFunctionDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*0*/function listAPIFiles(path: string): string[] {/*1*/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContentIs(t, "function listAPIFiles(path: string): string[] {") +} diff --git a/internal/fourslash/tests/gen/formatOnEnterInComment_test.go b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go new file mode 100644 index 0000000000..dace15358a --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnEnterInComment_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnEnterInComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` /** + * /*1*/ + */` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.VerifyCurrentFileContentIs(t, " /**\n * \n\n */") +} diff --git a/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go new file mode 100644 index 0000000000..bd80c51473 --- /dev/null +++ b/internal/fourslash/tests/gen/formatOnSemiColonAfterBreak_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatOnSemiColonAfterBreak(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `for (var a in b) { +break/**/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " break;") +} diff --git a/internal/fourslash/tests/gen/formatonkey01_test.go b/internal/fourslash/tests/gen/formatonkey01_test.go new file mode 100644 index 0000000000..cb5e869198 --- /dev/null +++ b/internal/fourslash/tests/gen/formatonkey01_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormatonkey01(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `switch (1) { + case 1: + { + /*1*/ + break; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, " }") +} diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go new file mode 100644 index 0000000000..023350a21f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineIfCondition_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAfterMultiLineIfCondition(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var foo; + if (foo && + foo) { +/*comment*/ // This is a comment + foo.toString(); + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToMarker(t, "comment") + f.VerifyCurrentLineContentIs(t, " // This is a comment") +} diff --git a/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go new file mode 100644 index 0000000000..8144204bab --- /dev/null +++ b/internal/fourslash/tests/gen/formattingAfterMultiLineString_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingAfterMultiLineString(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + stop() { + var s = "hello\/*1*/ +"/*2*/ + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, " var s = \"hello\\") +} diff --git a/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go new file mode 100644 index 0000000000..fe09257104 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingBlockInCaseClauses_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingBlockInCaseClauses(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `switch (1) { + case 1: + { + /*1*/ + break; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, " }") +} diff --git a/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go new file mode 100644 index 0000000000..a4395cd4ba --- /dev/null +++ b/internal/fourslash/tests/gen/formattingCommentsBeforeErrors_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingCommentsBeforeErrors(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module A { + interface B { + // a + // b + baz(); +/*0*/ // d /*1*/asd a + // e + foo(); + // f asd + // g as + bar(); + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContentIs(t, " // d ") +} diff --git a/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go new file mode 100644 index 0000000000..2b07d1606e --- /dev/null +++ b/internal/fourslash/tests/gen/formattingElseInsideAFunction_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingElseInsideAFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = function() { + if (true) { + /*1*/} else {/*2*/ +} + +// newline at the end of the file` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, " } else {") +} diff --git a/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go new file mode 100644 index 0000000000..81b03ebd13 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingEqualsBeforeBracketInTypeAlias_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingEqualsBeforeBracketInTypeAlias(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type X = [number]/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "type X = [number];") +} diff --git a/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go new file mode 100644 index 0000000000..daef5ffd27 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingExpressionsInIfCondition_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingExpressionsInIfCondition(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (a === 1 || + /*0*/b === 2 ||/*1*/ + c === 3) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "0") + f.VerifyCurrentLineContentIs(t, " b === 2 ||") +} diff --git a/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go new file mode 100644 index 0000000000..4e57d0401d --- /dev/null +++ b/internal/fourslash/tests/gen/formattingIfInElseBlock_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingIfInElseBlock(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) { +} +else { + if (true) { + /*1*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, " }") +} diff --git a/internal/fourslash/tests/gen/formattingInComment_test.go b/internal/fourslash/tests/gen/formattingInComment_test.go new file mode 100644 index 0000000000..47e1736fdf --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInComment_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class A { +foo( ); // /*1*/ +} +function foo() { var x; } // /*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "foo( ); // ;") + f.GoToMarker(t, "2") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, "function foo() { var x; } // }") +} diff --git a/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go new file mode 100644 index 0000000000..c9398e9e44 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInExpressionsInTsx_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInExpressionsInTsx(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: test.tsx +import * as React from "react"; +
+
` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " return true;") +} diff --git a/internal/fourslash/tests/gen/formattingInMultilineComments_test.go b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go new file mode 100644 index 0000000000..c85c0ba9b2 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingInMultilineComments_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingInMultilineComments(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = function() { + if (true) { + /*1*/} else {/*2*/ +} + +// newline at the end of the file` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, " } else {") +} diff --git a/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go b/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go new file mode 100644 index 0000000000..8c9b605c4c --- /dev/null +++ b/internal/fourslash/tests/gen/formattingKeywordAsIdentifier_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingKeywordAsIdentifier(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare var module/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "declare var module;") +} diff --git a/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go b/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go new file mode 100644 index 0000000000..cbd07ee7db --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOfChainedLambda_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOfChainedLambda(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var fn = (x: string) => ()=> alert(x)/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "var fn = (x: string) => () => alert(x);") +} diff --git a/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go b/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go new file mode 100644 index 0000000000..c1e9bd84d9 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnCloseBrace_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnCloseBrace(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.GoToBOF(t) + f.VerifyCurrentLineContentIs(t, "class foo {") +} diff --git a/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go b/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go new file mode 100644 index 0000000000..63d4d32827 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnDoWhileNoSemicolon_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnDoWhileNoSemicolon(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*2*/do { +/*3*/ for (var i = 0; i < 10; i++) +/*4*/ i -= 2 +/*5*/ }/*1*/while (1 !== 1)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentLineContentIs(t, "while (1 !== 1)") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContentIs(t, "do {") + f.GoToMarker(t, "3") + f.VerifyCurrentLineContentIs(t, " for (var i = 0; i < 10; i++)") + f.GoToMarker(t, "4") + f.VerifyCurrentLineContentIs(t, " i -= 2") + f.GoToMarker(t, "5") + f.VerifyCurrentLineContentIs(t, "}") +} diff --git a/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go b/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go new file mode 100644 index 0000000000..e33eac9ea9 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnterInComments_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnterInComments(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module me { + class A { + /* + */*1*/ + /*2*/} +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContentIs(t, " }") +} diff --git a/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go new file mode 100644 index 0000000000..7c65317874 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnterInStrings_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnterInStrings(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = /*1*/"unclosed string literal\/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, "var x = \"unclosed string literal\\") +} diff --git a/internal/fourslash/tests/gen/formattingOnEnter_test.go b/internal/fourslash/tests/gen/formattingOnEnter_test.go new file mode 100644 index 0000000000..c7b7ec50ce --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnEnter_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnEnter(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { } +class bar {/**/ } +// new line here` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.InsertLine(t, "") + f.VerifyCurrentFileContentIs(t, "class foo { }\nclass bar {\n}\n// new line here") +} diff --git a/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go b/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go new file mode 100644 index 0000000000..80cccc4386 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnNestedDoWhileByEnter_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnNestedDoWhileByEnter(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*2*/do{ +/*3*/do/*1*/{ +/*4*/do{ +/*5*/}while(a!==b) +/*6*/}while(a!==b) +/*7*/}while(a!==b)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentLineContentIs(t, " {") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContentIs(t, "do{") + f.GoToMarker(t, "3") + f.VerifyCurrentLineContentIs(t, " do") + f.GoToMarker(t, "4") + f.VerifyCurrentLineContentIs(t, "do{") + f.GoToMarker(t, "5") + f.VerifyCurrentLineContentIs(t, "}while(a!==b)") + f.GoToMarker(t, "6") + f.VerifyCurrentLineContentIs(t, "}while(a!==b)") + f.GoToMarker(t, "7") + f.VerifyCurrentLineContentIs(t, "}while(a!==b)") +} diff --git a/internal/fourslash/tests/gen/formattingOnSemiColon_test.go b/internal/fourslash/tests/gen/formattingOnSemiColon_test.go new file mode 100644 index 0000000000..99ecc442ea --- /dev/null +++ b/internal/fourslash/tests/gen/formattingOnSemiColon_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingOnSemiColon(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var a=b+c^d-e*++f` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, ";") + f.VerifyCurrentFileContentIs(t, "var a = b + c ^ d - e * ++f;") +} diff --git a/internal/fourslash/tests/gen/formattingRegexes_test.go b/internal/fourslash/tests/gen/formattingRegexes_test.go new file mode 100644 index 0000000000..22cf280b33 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingRegexes_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingRegexes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `removeAllButLast(sortedTypes, undefinedType, /keepNullableType**/ true)/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "removeAllButLast(sortedTypes, undefinedType, /keepNullableType**/ true);") +} diff --git a/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go b/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go new file mode 100644 index 0000000000..288dfc444f --- /dev/null +++ b/internal/fourslash/tests/gen/formattingSpaceAfterCommaBeforeOpenParen_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingSpaceAfterCommaBeforeOpenParen(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `foo(a,(b))/*1*/ +foo(a,(c).d)/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "foo(a, (b));") + f.GoToMarker(t, "2") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "foo(a, (c).d);") +} diff --git a/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go b/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go new file mode 100644 index 0000000000..832e78c4c0 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingTemplatesWithNewline_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingTemplatesWithNewline(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `` + "`" + `${1}` + "`" + `; +` + "`" + ` +` + "`" + `;/**/1` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "\n") + f.VerifyCurrentLineContentIs(t, "1") +} diff --git a/internal/fourslash/tests/gen/formattingTemplates_test.go b/internal/fourslash/tests/gen/formattingTemplates_test.go new file mode 100644 index 0000000000..1e16f4aef2 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingTemplates_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingTemplates(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `String.call ` + "`" + `${123}` + "`" + `/*1*/ +String.call ` + "`" + `${123} ${456}` + "`" + `/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "String.call`${123}`;") + f.GoToMarker(t, "2") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "String.call`${123} ${456}`;") +} diff --git a/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go b/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go new file mode 100644 index 0000000000..07ea193ce1 --- /dev/null +++ b/internal/fourslash/tests/gen/formattingWithMultilineComments_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFormattingWithMultilineComments(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `f(/* +/*2*/ */() => { /*1*/ });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.GoToMarker(t, "2") + f.VerifyCurrentLineContentIs(t, " */() => {") +} diff --git a/internal/fourslash/tests/gen/functionTypeFormatting_test.go b/internal/fourslash/tests/gen/functionTypeFormatting_test.go new file mode 100644 index 0000000000..a12f8fa7ed --- /dev/null +++ b/internal/fourslash/tests/gen/functionTypeFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionTypeFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: () => string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "var x: () => string;") +} diff --git a/internal/fourslash/tests/gen/functionTypes_test.go b/internal/fourslash/tests/gen/functionTypes_test.go new file mode 100644 index 0000000000..5eb38fab18 --- /dev/null +++ b/internal/fourslash/tests/gen/functionTypes_test.go @@ -0,0 +1,60 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunctionTypes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var f: Function; +function g() { } + +class C { + h: () => void ; + i(): number { return 5; } + static j = (e) => e; + static k() { return 'hi';} +} +var l = () => void 0; +var z = new C; + +f./*1*/apply(this, [1]); +g./*2*/arguments; +z.h./*3*/bind(undefined, 1, 2); +z.i./*4*/call(null) +C.j./*5*/length === 1; +typeof C.k./*6*/caller === 'function'; +l./*7*/prototype = Object.prototype;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyCompletions(t, []string{"1", "2", "3", "4", "5", "6"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: CompletionFunctionMembersWithPrototype, + }, + }) + f.VerifyCompletions(t, "7", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: CompletionFunctionMembersPlus( + []fourslash.CompletionsExpectedItem{ + "prototype", + }), + }, + }) +} diff --git a/internal/fourslash/tests/gen/funduleWithRecursiveReference_test.go b/internal/fourslash/tests/gen/funduleWithRecursiveReference_test.go new file mode 100644 index 0000000000..b4a8836b81 --- /dev/null +++ b/internal/fourslash/tests/gen/funduleWithRecursiveReference_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFunduleWithRecursiveReference(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export function C() {} + export module C { + export var /**/C = M.C + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "var M.C.C: typeof M.C", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/genericArityEnforcementAfterEdit_test.go b/internal/fourslash/tests/gen/genericArityEnforcementAfterEdit_test.go new file mode 100644 index 0000000000..d426fc519d --- /dev/null +++ b/internal/fourslash/tests/gen/genericArityEnforcementAfterEdit_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericArityEnforcementAfterEdit(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface G { } +/**/ +var v4: G, any>;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "") + f.Insert(t, " ") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/genericAssignmentCompat_test.go b/internal/fourslash/tests/gen/genericAssignmentCompat_test.go new file mode 100644 index 0000000000..1427c7da74 --- /dev/null +++ b/internal/fourslash/tests/gen/genericAssignmentCompat_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericAssignmentCompat(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Int { + + val(f: (t: T) => U): Int; + +} + +declare var v1: Int; + +var /*1*/v2/*2*/: Int = v1;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/genericCombinators1_test.go b/internal/fourslash/tests/gen/genericCombinators1_test.go new file mode 100644 index 0000000000..a2dd11aff9 --- /dev/null +++ b/internal/fourslash/tests/gen/genericCombinators1_test.go @@ -0,0 +1,76 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericCombinators1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Collection { + length: number; + add(x: T): void; + remove(x: T): boolean; +} +interface Combinators { + map(c: Collection, f: (x: T) => U): Collection; + map(c: Collection, f: (x: T) => any): Collection; +} +class A { + foo() { return this; } +} +class B { + foo(x: T): T { return null; } +} +var c2: Collection; +var c3: Collection>; +var c4: Collection; +var c5: Collection>; +var _: Combinators; +var rf1 = (x: number) => { return x.toFixed() }; +var rf2 = (x: Collection) => { return x.length }; +var rf3 = (x: A) => { return x.foo() }; +var /*9*/r1a = _.map(c2, (/*1*/x) => { return x.toFixed() }); +var /*10*/r1b = _.map(c2, rf1); +var /*11*/r2a = _.map(c3, (/*2*/x: Collection) => { return x.length }); +var /*12*/r2b = _.map(c3, rf2); +var /*13*/r3a = _.map(c4, (/*3*/x) => { return x.foo() }); +var /*14*/r3b = _.map(c4, rf3); +var /*15*/r4a = _.map(c5, (/*4*/x) => { return x.foo(1) }); +var /*17*/r5a = _.map(c2, (/*5*/x) => { return x.toFixed() }); +var /*18*/r5b = _.map(c2, rf1); +var /*19*/r6a = _.map, number>(/*6*/c3, (x: Collection) => { return x.length }); +var /*20*/r6b = _.map, number>(c3, rf2); +var /*21*/r7a = _.map(c4, (/*7*/x: A) => { return x.foo() }); +var /*22*/r7b = _.map(c4, rf3); +var /*23*/r8a = _.map(c5, (/*8*/x) => { return x.foo() });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "2", "(parameter) x: Collection", "") + f.VerifyQuickInfoAt(t, "3", "(parameter) x: A", "") + f.VerifyQuickInfoAt(t, "4", "(parameter) x: B", "") + f.VerifyQuickInfoAt(t, "5", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "6", "var c3: Collection>", "") + f.VerifyQuickInfoAt(t, "7", "(parameter) x: A", "") + f.VerifyQuickInfoAt(t, "8", "(parameter) x: any", "") + f.VerifyQuickInfoAt(t, "9", "var r1a: Collection", "") + f.VerifyQuickInfoAt(t, "10", "var r1b: Collection", "") + f.VerifyQuickInfoAt(t, "11", "var r2a: Collection", "") + f.VerifyQuickInfoAt(t, "12", "var r2b: Collection", "") + f.VerifyQuickInfoAt(t, "13", "var r3a: Collection", "") + f.VerifyQuickInfoAt(t, "14", "var r3b: Collection", "") + f.VerifyQuickInfoAt(t, "15", "var r4a: Collection", "") + f.VerifyQuickInfoAt(t, "17", "var r5a: Collection", "") + f.VerifyQuickInfoAt(t, "18", "var r5b: Collection", "") + f.VerifyQuickInfoAt(t, "19", "var r6a: Collection", "") + f.VerifyQuickInfoAt(t, "20", "var r6b: Collection", "") + f.VerifyQuickInfoAt(t, "21", "var r7a: Collection", "") + f.VerifyQuickInfoAt(t, "22", "var r7b: Collection", "") + f.VerifyQuickInfoAt(t, "23", "var r8a: Collection", "") + f.VerifyErrorExistsBetweenMarkers(t, "error1", "error2") +} diff --git a/internal/fourslash/tests/gen/genericInterfacePropertyInference1_test.go b/internal/fourslash/tests/gen/genericInterfacePropertyInference1_test.go new file mode 100644 index 0000000000..943ec1d106 --- /dev/null +++ b/internal/fourslash/tests/gen/genericInterfacePropertyInference1_test.go @@ -0,0 +1,148 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericInterfacePropertyInference1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + x: number; +} + +var anInterface: I; +interface IG { + x: T; +} +var aGenericInterface: IG; + +class C implements IG { + x: T; +} + +interface Foo { + prim1: number; + prim2: string; + ofT: T; + ofFooNum: Foo; + ofInterface: I; + ofIG4: { x: number }; + ofIG6: { x: T }; + ofC2: C; + ofC4: C<{ x: T }> +} + +var f: Foo; +var f2: Foo; +var f3: Foo; +var f4: Foo<{ x: number }>; +var f5: Foo>; + +// T is any +var f_/*a1*/r1 = f.prim1; +var f_/*a2*/r2 = f.prim2; +var f_/*a3*/r3 = f.ofT; +var f_/*a4*/r5 = f.ofFooNum; +var f_/*a5*/r8 = f.ofInterface; +var f_/*a6*/r12 = f.ofIG4; +var f_/*a7*/r14 = f.ofIG6; +var f_/*a8*/r18 = f.ofC2; +var f_/*a9*/r20 = f.ofC4; + +// T is number +var f2_/*b1*/r1 = f2.prim1; +var f2_/*b2*/r2 = f2.prim2; +var f2_/*b3*/r3 = f2.ofT; +var f2_/*b4*/r5 = f2.ofFooNum; +var f2_/*b5*/r8 = f2.ofInterface; +var f2_/*b6*/r12 = f2.ofIG4; +var f2_/*b7*/r14 = f2.ofIG6; +var f2_/*b8*/r18 = f2.ofC2; +var f2_/*b9*/r20 = f2.ofC4; + +// T is I +var f3_/*c1*/r1 = f3.prim1; +var f3_/*c2*/r2 = f3.prim2; +var f3_/*c3*/r3 = f3.ofT; +var f3_/*c4*/r5 = f3.ofFooNum; +var f3_/*c5*/r8 = f3.ofInterface; +var f3_/*c6*/r12 = f3.ofIG4; +var f3_/*c7*/r14 = f3.ofIG6; +var f3_/*c8*/r18 = f3.ofC2; +var f3_/*c9*/r20 = f3.ofC4; + +// T is {x: number} +var f4_/*d1*/r1 = f4.prim1; +var f4_/*d2*/r2 = f4.prim2; +var f4_/*d3*/r3 = f4.ofT; +var f4_/*d4*/r5 = f4.ofFooNum; +var f4_/*d5*/r8 = f4.ofInterface; +var f4_/*d6*/r12 = f4.ofIG4; +var f4_/*d7*/r14 = f4.ofIG6; +var f4_/*d8*/r18 = f4.ofC2; +var f4_/*d9*/r20 = f4.ofC4; + +// T is Foo +var f5_/*e1*/r1 = f5.prim1; +var f5_/*e2*/r2 = f5.prim2; +var f5_/*e3*/r3 = f5.ofT; +var f5_/*e4*/r5 = f5.ofFooNum; +var f5_/*e5*/r8 = f5.ofInterface; +var f5_/*e6*/r12 = f5.ofIG4; +var f5_/*e7*/r14 = f5.ofIG6; +var f5_/*e8*/r18 = f5.ofC2; +var f5_/*e9*/r20 = f5.ofC4;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyQuickInfoAt(t, "a1", "var f_r1: number", "") + f.VerifyQuickInfoAt(t, "a2", "var f_r2: string", "") + f.VerifyQuickInfoAt(t, "a3", "var f_r3: any", "") + f.VerifyQuickInfoAt(t, "a4", "var f_r5: Foo", "") + f.VerifyQuickInfoAt(t, "a5", "var f_r8: I", "") + f.VerifyQuickInfoAt(t, "a6", "var f_r12: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "a7", "var f_r14: {\n x: any;\n}", "") + f.VerifyQuickInfoAt(t, "a8", "var f_r18: C", "") + f.VerifyQuickInfoAt(t, "a9", "var f_r20: C<{\n x: any;\n}>", "") + f.VerifyQuickInfoAt(t, "b1", "var f2_r1: number", "") + f.VerifyQuickInfoAt(t, "b2", "var f2_r2: string", "") + f.VerifyQuickInfoAt(t, "b3", "var f2_r3: number", "") + f.VerifyQuickInfoAt(t, "b4", "var f2_r5: Foo", "") + f.VerifyQuickInfoAt(t, "b5", "var f2_r8: I", "") + f.VerifyQuickInfoAt(t, "b6", "var f2_r12: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "b7", "var f2_r14: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "b8", "var f2_r18: C", "") + f.VerifyQuickInfoAt(t, "b9", "var f2_r20: C<{\n x: number;\n}>", "") + f.VerifyQuickInfoAt(t, "c1", "var f3_r1: number", "") + f.VerifyQuickInfoAt(t, "c2", "var f3_r2: string", "") + f.VerifyQuickInfoAt(t, "c3", "var f3_r3: I", "") + f.VerifyQuickInfoAt(t, "c4", "var f3_r5: Foo", "") + f.VerifyQuickInfoAt(t, "c5", "var f3_r8: I", "") + f.VerifyQuickInfoAt(t, "c6", "var f3_r12: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "c7", "var f3_r14: {\n x: I;\n}", "") + f.VerifyQuickInfoAt(t, "c8", "var f3_r18: C", "") + f.VerifyQuickInfoAt(t, "c9", "var f3_r20: C<{\n x: I;\n}>", "") + f.VerifyQuickInfoAt(t, "d1", "var f4_r1: number", "") + f.VerifyQuickInfoAt(t, "d2", "var f4_r2: string", "") + f.VerifyQuickInfoAt(t, "d3", "var f4_r3: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "d4", "var f4_r5: Foo", "") + f.VerifyQuickInfoAt(t, "d5", "var f4_r8: I", "") + f.VerifyQuickInfoAt(t, "d6", "var f4_r12: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "d7", "var f4_r14: {\n x: {\n x: number;\n };\n}", "") + f.VerifyQuickInfoAt(t, "d8", "var f4_r18: C", "") + f.VerifyQuickInfoAt(t, "d9", "var f4_r20: C<{\n x: {\n x: number;\n };\n}>", "") + f.VerifyQuickInfoAt(t, "e1", "var f5_r1: number", "") + f.VerifyQuickInfoAt(t, "e2", "var f5_r2: string", "") + f.VerifyQuickInfoAt(t, "e3", "var f5_r3: Foo", "") + f.VerifyQuickInfoAt(t, "e4", "var f5_r5: Foo", "") + f.VerifyQuickInfoAt(t, "e5", "var f5_r8: I", "") + f.VerifyQuickInfoAt(t, "e6", "var f5_r12: {\n x: number;\n}", "") + f.VerifyQuickInfoAt(t, "e7", "var f5_r14: {\n x: Foo;\n}", "") + f.VerifyQuickInfoAt(t, "e8", "var f5_r18: C", "") + f.VerifyQuickInfoAt(t, "e9", "var f5_r20: C<{\n x: Foo;\n}>", "") +} diff --git a/internal/fourslash/tests/gen/genericInterfacePropertyInference2_test.go b/internal/fourslash/tests/gen/genericInterfacePropertyInference2_test.go new file mode 100644 index 0000000000..1f158101a7 --- /dev/null +++ b/internal/fourslash/tests/gen/genericInterfacePropertyInference2_test.go @@ -0,0 +1,104 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericInterfacePropertyInference2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + x: number; +} + +var anInterface: I; +interface IG { + x: T; +} +var aGenericInterface: IG; + +class C implements IG { + x: T; +} + +interface Foo { + ofFooT: Foo; + ofFooFooNum: Foo>; // should be error? + ofIG: IG; + ofIG5: { x: Foo; }; // same as ofIG3 + ofC1: C; +} + +var f: Foo; +var f2: Foo; +var f3: Foo; +var f4: Foo<{ x: number }>; +var f5: Foo>; + +// T is any +var f_/*a1*/r4 = f.ofFooT; +var f_/*a2*/r7 = f.ofFooFooNum; +var f_/*a3*/r9 = f.ofIG; +var f_/*a5*/r13 = f.ofIG5; +var f_/*a7*/r17 = f.ofC1; + +// T is number +var f2_/*b1*/r4 = f2.ofFooT; +var f2_/*b2*/r7 = f2.ofFooFooNum; +var f2_/*b3*/r9 = f2.ofIG; +var f2_/*b5*/r13 = f2.ofIG5; +var f2_/*b7*/r17 = f2.ofC1; + +// T is I} +var f3_/*c1*/r4 = f3.ofFooT; +var f3_/*c2*/r7 = f3.ofFooFooNum; +var f3_/*c3*/r9 = f3.ofIG; +var f3_/*c5*/r13 = f3.ofIG5; +var f3_/*c7*/r17 = f3.ofC1; + +// T is {x: number} +var f4_/*d1*/r4 = f4.ofFooT; +var f4_/*d2*/r7 = f4.ofFooFooNum; +var f4_/*d3*/r9 = f4.ofIG; +var f4_/*d5*/r13 = f4.ofIG5; +var f4_/*d7*/r17 = f4.ofC1; + +// T is Foo +var f5_/*e1*/r4 = f5.ofFooT; +var f5_/*e2*/r7 = f5.ofFooFooNum; +var f5_/*e3*/r9 = f5.ofIG; +var f5_/*e5*/r13 = f5.ofIG5; +var f5_/*e7*/r17 = f5.ofC1;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyQuickInfoAt(t, "a1", "var f_r4: Foo", "") + f.VerifyQuickInfoAt(t, "a2", "var f_r7: Foo>", "") + f.VerifyQuickInfoAt(t, "a3", "var f_r9: IG", "") + f.VerifyQuickInfoAt(t, "a5", "var f_r13: {\n x: Foo;\n}", "") + f.VerifyQuickInfoAt(t, "a7", "var f_r17: C", "") + f.VerifyQuickInfoAt(t, "b1", "var f2_r4: Foo", "") + f.VerifyQuickInfoAt(t, "b2", "var f2_r7: Foo>", "") + f.VerifyQuickInfoAt(t, "b3", "var f2_r9: IG", "") + f.VerifyQuickInfoAt(t, "b5", "var f2_r13: {\n x: Foo;\n}", "") + f.VerifyQuickInfoAt(t, "b7", "var f2_r17: C", "") + f.VerifyQuickInfoAt(t, "c1", "var f3_r4: Foo", "") + f.VerifyQuickInfoAt(t, "c2", "var f3_r7: Foo>", "") + f.VerifyQuickInfoAt(t, "c3", "var f3_r9: IG", "") + f.VerifyQuickInfoAt(t, "c5", "var f3_r13: {\n x: Foo;\n}", "") + f.VerifyQuickInfoAt(t, "c7", "var f3_r17: C", "") + f.VerifyQuickInfoAt(t, "d1", "var f4_r4: Foo<{\n x: number;\n}>", "") + f.VerifyQuickInfoAt(t, "d2", "var f4_r7: Foo>", "") + f.VerifyQuickInfoAt(t, "d3", "var f4_r9: IG<{\n x: number;\n}>", "") + f.VerifyQuickInfoAt(t, "d5", "var f4_r13: {\n x: Foo<{\n x: number;\n }>;\n}", "") + f.VerifyQuickInfoAt(t, "d7", "var f4_r17: C<{\n x: number;\n}>", "") + f.VerifyQuickInfoAt(t, "e1", "var f5_r4: Foo>", "") + f.VerifyQuickInfoAt(t, "e2", "var f5_r7: Foo>", "") + f.VerifyQuickInfoAt(t, "e3", "var f5_r9: IG>", "") + f.VerifyQuickInfoAt(t, "e5", "var f5_r13: {\n x: Foo>;\n}", "") + f.VerifyQuickInfoAt(t, "e7", "var f5_r17: C>", "") +} diff --git a/internal/fourslash/tests/gen/genericInterfaceWithInheritanceEdit1_test.go b/internal/fourslash/tests/gen/genericInterfaceWithInheritanceEdit1_test.go new file mode 100644 index 0000000000..85cc4d6813 --- /dev/null +++ b/internal/fourslash/tests/gen/genericInterfaceWithInheritanceEdit1_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericInterfaceWithInheritanceEdit1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface ChainedObject { + values(): ChainedArray; + pairs(): ChainedArray; + extend(...sources: any[]): ChainedObject; + + value(): T; +} +interface ChainedArray extends ChainedObject> { + + extend(...sources: any[]): ChainedArray; +} + /*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.Insert(t, " ") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/genericMapTyping1_test.go b/internal/fourslash/tests/gen/genericMapTyping1_test.go new file mode 100644 index 0000000000..2c802769cd --- /dev/null +++ b/internal/fourslash/tests/gen/genericMapTyping1_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericMapTyping1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Iterator_ { + (value: T, index: any, list: any): U; +} +interface WrappedArray { + map(iterator: Iterator_, context?: any): U[]; +} +interface Underscore { + (list: T[]): WrappedArray; + map(list: T[], iterator: Iterator_, context?: any): U[]; +} +declare var _: Underscore; +var aa: string[]; +var b/*1*/b = _.map(aa, x/*7*/x => xx.length); // should be number[] +var c/*2*/c = _(aa).map(x/*8*/x => xx.length); // should be number[] +var d/*3*/d = aa.map(xx => x/*9*/x.length); // should be number[] +var aaa: any[]; +var b/*4*/bb = _.map(aaa, xx => xx.length); // should be any[] +var c/*5*/cc = _(aaa).map(xx => xx.length); // Should not error, should be any[] +var d/*6*/dd = aaa.map(xx => xx.length); // should not error, should be any[]` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyQuickInfoAt(t, "1", "var bb: number[]", "") + f.VerifyQuickInfoAt(t, "2", "var cc: number[]", "") + f.VerifyQuickInfoAt(t, "3", "var dd: number[]", "") + f.VerifyQuickInfoAt(t, "4", "var bbb: any[]", "") + f.VerifyQuickInfoAt(t, "5", "var ccc: any[]", "") + f.VerifyQuickInfoAt(t, "6", "var ddd: any[]", "") + f.VerifyQuickInfoAt(t, "7", "(parameter) xx: string", "") + f.VerifyQuickInfoAt(t, "8", "(parameter) xx: string", "") + f.VerifyQuickInfoAt(t, "9", "(parameter) xx: string", "") +} diff --git a/internal/fourslash/tests/gen/genericMethodParam_test.go b/internal/fourslash/tests/gen/genericMethodParam_test.go new file mode 100644 index 0000000000..b27f512b8a --- /dev/null +++ b/internal/fourslash/tests/gen/genericMethodParam_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericMethodParam(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*1*/ +} +/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.InsertLine(t, "constructor(){}") + f.InsertLine(t, "foo(a: T) {") + f.InsertLine(t, " return a;") + f.InsertLine(t, "}") + f.VerifyNoErrors(t) + f.GoToMarker(t, "2") + f.InsertLine(t, "var x = new C();") + f.InsertLine(t, "var y: number = x.foo(5);") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/genericObjectBaseType_test.go b/internal/fourslash/tests/gen/genericObjectBaseType_test.go new file mode 100644 index 0000000000..cd098735fe --- /dev/null +++ b/internal/fourslash/tests/gen/genericObjectBaseType_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericObjectBaseType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + constructor(){} + foo(a: T) { + return a.toString(); + } +} +var x = new C(); +var y: string = x.foo("hi"); +/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/genericRespecialization1_test.go b/internal/fourslash/tests/gen/genericRespecialization1_test.go new file mode 100644 index 0000000000..86d5ae6f0e --- /dev/null +++ b/internal/fourslash/tests/gen/genericRespecialization1_test.go @@ -0,0 +1,88 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericRespecialization1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Food { + private amount: number; + constructor(public name: string) { + this.amount = 100; + } + public eat(amountToEat: number): boolean { + this.amount -= amountToEat; + if (this.amount <= 0) { + this.amount = 0; + return false; + } + else { + return true; + } + } +} +class IceCream extends Food { + private isDairyFree: boolean; + constructor(public flavor: string) { + super("Ice Cream"); + } +} +class Cookie extends Food { + constructor(public flavor: string, public isGlutenFree: boolean) { + super("Cookie"); + } +} +class Slug { + // This is NOT a food!!! +} +class GenericMonster { + private name: string; + private age: number; + private isFriendly: boolean; + constructor(name: string, age: number, isFriendly: boolean, private food: T, public variant: V) { + this.name = name; + this.age = age; + this.isFriendly = isFriendly; + } + public getFood(): T { + return this.food; + } + public getVariant(): V { + return this.variant; + } + public eatFood(amountToEat: number): boolean { + return this.food.eat(amountToEat); + } + public sayGreeting(): string { + return ("My name is " + this.name + ", and my age is " + this.age + ". I enjoy eating " + this.food.name + " and my variant is " + this.variant); + } +} +class GenericPlanet> { + constructor(public name: string, public solarSystem: string, public species: T) { } +} +var cookie = new Cookie("Chocolate Chip", false); +var cookieMonster = new GenericMonster("Cookie Monster", 50, true, cookie, "hello"); +var sesameStreet = new GenericPlanet>("Sesame Street", "Alpha Centuri", cookieMonster); +class GenericPlanet2{ + constructor(public name: string, public solarSystem: string, public species: GenericMonster) { } +} + /*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.InsertLine(t, "") + f.InsertLine(t, "") + f.VerifyNoErrors(t) + f.GoToMarker(t, "2") + f.DeleteAtCaret(t, 6) + f.Insert(t, "any") + f.VerifyNoErrors(t) + f.InsertLine(t, "var narnia = new GenericPlanet2(") +} diff --git a/internal/fourslash/tests/gen/genericSignaturesAreProperlyCleaned_test.go b/internal/fourslash/tests/gen/genericSignaturesAreProperlyCleaned_test.go new file mode 100644 index 0000000000..034f9e7d1d --- /dev/null +++ b/internal/fourslash/tests/gen/genericSignaturesAreProperlyCleaned_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericSignaturesAreProperlyCleaned(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Int { +val(f: (t: T) => U): Int; +} +declare var v1: Int; +var v2: Int = v1/*1*/;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "1") + f.DeleteAtCaret(t, 1) + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/getDeclarationDiagnostics_test.go b/internal/fourslash/tests/gen/getDeclarationDiagnostics_test.go new file mode 100644 index 0000000000..9b413d5a16 --- /dev/null +++ b/internal/fourslash/tests/gen/getDeclarationDiagnostics_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetDeclarationDiagnostics(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @declaration: true +// @outFile: true +// @Filename: inputFile1.ts +module m { + export function foo() { + class C implements I { private a; } + interface I { } + return C; + } +} /*1*/ +// @Filename: input2.ts +var x = "hello world"; /*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) +} diff --git a/internal/fourslash/tests/gen/getPreProcessedFile_test.go b/internal/fourslash/tests/gen/getPreProcessedFile_test.go new file mode 100644 index 0000000000..158488326e --- /dev/null +++ b/internal/fourslash/tests/gen/getPreProcessedFile_test.go @@ -0,0 +1,42 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetPreProcessedFile(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @moduleResolution: classic +// @Filename: refFile1.ts +class D { } +// @Filename: refFile2.ts +export class E {} +// @Filename: main.ts +// @ResolveReference: true +/// +/// +/*3*/////*4*/ +import ref2 = require("refFile2"); +import noExistref2 = require(/*5*/"NotExistRefFile2"/*6*/); +import invalidRef1 /*7*/require/*8*/("refFile2"); +import invalidRef2 = /*9*/requi/*10*/(/*10A*/"refFile2"); +var obj: /*11*/C/*12*/; +var obj1: D; +var obj2: ref2.E;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "main.ts") + f.VerifyNumberOfErrorsInCurrentFile(t, 7) + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyErrorExistsBetweenMarkers(t, "3", "4") + f.VerifyErrorExistsBetweenMarkers(t, "5", "6") + f.VerifyErrorExistsBetweenMarkers(t, "7", "8") + f.VerifyErrorExistsBetweenMarkers(t, "9", "10") + f.VerifyErrorExistsBetweenMarkers(t, "10", "10A") + f.VerifyErrorExistsBetweenMarkers(t, "11", "12") +} diff --git a/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration1_test.go b/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration1_test.go new file mode 100644 index 0000000000..569d4306ed --- /dev/null +++ b/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration1_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetSemanticDiagnosticForDeclaration1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @declaration: true +// @Filename: File.d.ts +declare var v: string;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration_test.go b/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration_test.go new file mode 100644 index 0000000000..ff859c6568 --- /dev/null +++ b/internal/fourslash/tests/gen/getSemanticDiagnosticForDeclaration_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetSemanticDiagnosticForDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: CommonJS +// @declaration: true +export function /*1*/foo/*2*/() { + interface privateInterface {} + class Bar implements privateInterface { private a; } + return Bar; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/getSemanticDiagnosticForNoDeclaration_test.go b/internal/fourslash/tests/gen/getSemanticDiagnosticForNoDeclaration_test.go new file mode 100644 index 0000000000..30f776d444 --- /dev/null +++ b/internal/fourslash/tests/gen/getSemanticDiagnosticForNoDeclaration_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGetSemanticDiagnosticForNoDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: CommonJS +interface privateInterface {} +export class Bar implements /*1*/privateInterface/*2*/{ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/goToDefinitionImportMeta_test.go b/internal/fourslash/tests/gen/goToDefinitionImportMeta_test.go new file mode 100644 index 0000000000..888eb2234b --- /dev/null +++ b/internal/fourslash/tests/gen/goToDefinitionImportMeta_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGoToDefinitionImportMeta(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: esnext +// @Filename: foo.ts +/// +/// +import.me/*reference*/ta; +//@Filename: bar.d.ts +interface ImportMeta { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineGoToDefinition(t, true, "reference") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/goToDefinitionSignatureAlias_test.go b/internal/fourslash/tests/gen/goToDefinitionSignatureAlias_test.go new file mode 100644 index 0000000000..a6d9f9bda7 --- /dev/null +++ b/internal/fourslash/tests/gen/goToDefinitionSignatureAlias_test.go @@ -0,0 +1,51 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGoToDefinitionSignatureAlias(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @jsx: preserve +// @Filename: /a.tsx +function /*f*/f() {} +const /*g*/g = f; +const /*h*/h = g; +[|/*useF*/f|](); +[|/*useG*/g|](); +[|/*useH*/h|](); +const /*i*/i = () => 0; +const /*iFn*/iFn = function () { return 0; }; +const /*j*/j = i; +[|/*useI*/i|](); +[|/*useIFn*/iFn|](); +[|/*useJ*/j|](); +const o = { /*m*/m: () => 0 }; +o.[|/*useM*/m|](); +const oFn = { /*mFn*/mFn: function () { return 0; } }; +oFn.[|/*useMFn*/mFn|](); +class Component { /*componentCtr*/constructor(props: {}) {} } +type ComponentClass = /*ComponentClass*/new () => Component; +interface ComponentClass2 { /*ComponentClass2*/new(): Component; } + +class /*MyComponent*/MyComponent extends Component {} +<[|/*jsxMyComponent*/MyComponent|] />; +new [|/*newMyComponent*/MyComponent|]({}); + +declare const /*MyComponent2*/MyComponent2: ComponentClass; +<[|/*jsxMyComponent2*/MyComponent2|] />; +new [|/*newMyComponent2*/MyComponent2|](); + +declare const /*MyComponent3*/MyComponent3: ComponentClass2; +<[|/*jsxMyComponent3*/MyComponent3|] />; +new [|/*newMyComponent3*/MyComponent3|]();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineGoToDefinition(t, true, "useF", "useG", "useH", "useI", "useIFn", "useJ", "useM", "useMFn", "jsxMyComponent", "newMyComponent", "jsxMyComponent2", "newMyComponent2", "jsxMyComponent3", "newMyComponent3") +} diff --git a/internal/fourslash/tests/gen/identifierErrorRecovery_test.go b/internal/fourslash/tests/gen/identifierErrorRecovery_test.go new file mode 100644 index 0000000000..bbb62ec8f6 --- /dev/null +++ b/internal/fourslash/tests/gen/identifierErrorRecovery_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIdentifierErrorRecovery(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var /*1*/export/*2*/; +var foo; +var /*3*/class/*4*/; +var bar;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyErrorExistsBetweenMarkers(t, "3", "4") + f.VerifyNumberOfErrorsInCurrentFile(t, 3) + f.GoToEOF(t) + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "foo", + "bar", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/importMetaCompletionDetails_test.go b/internal/fourslash/tests/gen/importMetaCompletionDetails_test.go new file mode 100644 index 0000000000..bce458240a --- /dev/null +++ b/internal/fourslash/tests/gen/importMetaCompletionDetails_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportMetaCompletionDetails(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: index.mts +// @module: Node16 +// @strict: true +let x = import.meta/**/;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "meta", + Detail: PtrTo("(property) ImportMetaExpression.meta: ImportMeta"), + }, + }, + }, + }) + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/incompatibleOverride_test.go b/internal/fourslash/tests/gen/incompatibleOverride_test.go new file mode 100644 index 0000000000..d001ad4156 --- /dev/null +++ b/internal/fourslash/tests/gen/incompatibleOverride_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncompatibleOverride(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { xyz: string; } +class Bar extends Foo { /*1*/xyz/*2*/: number = 1; } +class Baz extends Foo { public /*3*/xyz/*4*/: number = 2; } +class /*5*/Baf/*6*/ extends Foo { + constructor(public xyz: number) { + super(); + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyErrorExistsBetweenMarkers(t, "3", "4") + f.VerifyErrorExistsBetweenMarkers(t, "5", "6") + f.VerifyNumberOfErrorsInCurrentFile(t, 3) +} diff --git a/internal/fourslash/tests/gen/incrementalEditInvocationExpressionAboveInterfaceDeclaration_test.go b/internal/fourslash/tests/gen/incrementalEditInvocationExpressionAboveInterfaceDeclaration_test.go new file mode 100644 index 0000000000..0003424816 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalEditInvocationExpressionAboveInterfaceDeclaration_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalEditInvocationExpressionAboveInterfaceDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare function alert(message?: any): void; +/*1*/ +interface Foo { + setISO8601(dString): Date; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "alert(") + f.VerifySignatureHelp(t, fourslash.VerifySignatureHelpOptions{Text: "alert(message?: any): void"}) + f.VerifyErrorExistsAfterMarker(t, "1") +} diff --git a/internal/fourslash/tests/gen/incrementalParsingDynamicImport1_test.go b/internal/fourslash/tests/gen/incrementalParsingDynamicImport1_test.go new file mode 100644 index 0000000000..4b2f9b2036 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingDynamicImport1_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingDynamicImport1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @lib: es6 +// @Filename: ./foo.ts +export function bar() { return 1; } +var x1 = import("./foo"); +x1.then(foo => { + var s: string = foo.bar(); +}) +/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "1") + f.Insert(t, " ") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingDynamicImport2_test.go b/internal/fourslash/tests/gen/incrementalParsingDynamicImport2_test.go new file mode 100644 index 0000000000..29b5ec63e9 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingDynamicImport2_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingDynamicImport2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @lib: es2015 +// @Filename: ./foo.ts +export function bar() { return 1; } +// @Filename: ./0.ts +/*1*/ import { bar } from "./foo"` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "1") + f.Insert(t, "var x = ") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingDynamicImport3_test.go b/internal/fourslash/tests/gen/incrementalParsingDynamicImport3_test.go new file mode 100644 index 0000000000..546124532f --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingDynamicImport3_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingDynamicImport3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @lib: es2015 +// @Filename: ./foo.ts +export function bar() { return 1; } +// @Filename: ./0.ts +var x = import/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "1") + f.Insert(t, "(") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingDynamicImport4_test.go b/internal/fourslash/tests/gen/incrementalParsingDynamicImport4_test.go new file mode 100644 index 0000000000..55d037d2d1 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingDynamicImport4_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingDynamicImport4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @lib: es2015 +// @Filename: ./foo.ts +export function bar() { return 1; } +// @Filename: ./0.ts +/*1*/ +import { bar } from "./foo"` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "1") + f.Insert(t, "import") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait1_test.go b/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait1_test.go new file mode 100644 index 0000000000..24a798af15 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait1_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingTopLevelAwait1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @target: esnext +// @module: esnext +// @Filename: ./foo.ts +await(1); +/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "1") + f.Insert(t, "export {};") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.ReplaceLine(t, 1, "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait2_test.go b/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait2_test.go new file mode 100644 index 0000000000..68d68bf192 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalParsingTopLevelAwait2_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalParsingTopLevelAwait2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @target: esnext +// @module: esnext +// @Filename: ./foo.ts +export {}; +/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "1") + f.Insert(t, "await(1);") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.ReplaceLine(t, 1, "") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) +} diff --git a/internal/fourslash/tests/gen/incrementalResolveAccessor_test.go b/internal/fourslash/tests/gen/incrementalResolveAccessor_test.go new file mode 100644 index 0000000000..a51e775984 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalResolveAccessor_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalResolveAccessor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class c1 { + get p1(): string { + return "30"; + } + set p1(a: number) { + a = "30"; + } +} +var val = new c1(); +var b = val.p1; +/*1*/b;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "var b: string", "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalResolveConstructorDeclaration_test.go b/internal/fourslash/tests/gen/incrementalResolveConstructorDeclaration_test.go new file mode 100644 index 0000000000..04f2b1dd17 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalResolveConstructorDeclaration_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalResolveConstructorDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class c1 { + private b: number; + constructor(a: string) { + this.b = a; + } +} +var val = new c1("hello"); +/*1*/val;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "var val: c1", "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalResolveFunctionPropertyAssignment_test.go b/internal/fourslash/tests/gen/incrementalResolveFunctionPropertyAssignment_test.go new file mode 100644 index 0000000000..20a808b05d --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalResolveFunctionPropertyAssignment_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalResolveFunctionPropertyAssignment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function bar(indexer: { getLength(): number; getTypeAtIndex(index: number): string; }): string { + return indexer.getTypeAtIndex(indexer.getLength() - 1); +} +function foo(a: string[]) { + return bar({ + getLength(): number { + return "a.length"; + }, + getTypeAtIndex(index: number) { + switch (index) { + case 0: return a[0]; + case 1: return a[1]; + case 2: return a[2]; + default: return "invalid"; + } + } + }); +} +var val = foo(["myString1", "myString2"]); +/*1*/val;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "var val: string", "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/incrementalUpdateToClassImplementingGenericClass_test.go b/internal/fourslash/tests/gen/incrementalUpdateToClassImplementingGenericClass_test.go new file mode 100644 index 0000000000..9c58632a37 --- /dev/null +++ b/internal/fourslash/tests/gen/incrementalUpdateToClassImplementingGenericClass_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIncrementalUpdateToClassImplementingGenericClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare function alert(message?: string): void; +class Animal { + constructor(public name: T) { } + move(meters: number) { + alert(this.name + " moved " + meters + "m."); + } +} +class Animal2 extends Animal { + constructor(name: string) { super(name); } + /*1*/get name2() { return this.name; } +} +var a = new Animal2('eprst');` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyNoErrors(t) + f.Insert(t, "//") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go b/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go new file mode 100644 index 0000000000..12ad10e3af --- /dev/null +++ b/internal/fourslash/tests/gen/indentAfterFunctionClosingBraces_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIndentAfterFunctionClosingBraces(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { + public f() { + return 0; + /*1*/}/*2*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.InsertLine(t, "") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, " }") +} diff --git a/internal/fourslash/tests/gen/inheritedModuleMembersForClodule2_test.go b/internal/fourslash/tests/gen/inheritedModuleMembersForClodule2_test.go new file mode 100644 index 0000000000..c61bab4416 --- /dev/null +++ b/internal/fourslash/tests/gen/inheritedModuleMembersForClodule2_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInheritedModuleMembersForClodule2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export module A { + var o; + } +} +module M { + export class A { a = 1;} +} +module M { + export class A { /**/b } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyQuickInfoExists(t) + f.VerifyNumberOfErrorsInCurrentFile(t, 4) +} diff --git a/internal/fourslash/tests/gen/insertReturnStatementInDuplicateIdentifierFunction_test.go b/internal/fourslash/tests/gen/insertReturnStatementInDuplicateIdentifierFunction_test.go new file mode 100644 index 0000000000..4ca0e44681 --- /dev/null +++ b/internal/fourslash/tests/gen/insertReturnStatementInDuplicateIdentifierFunction_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertReturnStatementInDuplicateIdentifierFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo { }; +function foo() { /**/ }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyNumberOfErrorsInCurrentFile(t, 2) + f.Insert(t, "return null;") + f.VerifyNumberOfErrorsInCurrentFile(t, 2) +} diff --git a/internal/fourslash/tests/gen/interfaceExtendsPrimitive_test.go b/internal/fourslash/tests/gen/interfaceExtendsPrimitive_test.go new file mode 100644 index 0000000000..74a36b951a --- /dev/null +++ b/internal/fourslash/tests/gen/interfaceExtendsPrimitive_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInterfaceExtendsPrimitive(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface x extends /*1*/string/*2*/ { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/invalidRestArgError_test.go b/internal/fourslash/tests/gen/invalidRestArgError_test.go new file mode 100644 index 0000000000..57e0035ece --- /dev/null +++ b/internal/fourslash/tests/gen/invalidRestArgError_test.go @@ -0,0 +1,18 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInvalidRestArgError(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function b(.../*1*/)/*2*/ {} ` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/invertedCloduleAfterQuickInfo_test.go b/internal/fourslash/tests/gen/invertedCloduleAfterQuickInfo_test.go new file mode 100644 index 0000000000..51344ca07f --- /dev/null +++ b/internal/fourslash/tests/gen/invertedCloduleAfterQuickInfo_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInvertedCloduleAfterQuickInfo(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + module A { + var o; + } + class A { + /**/c + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyQuickInfoExists(t) + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/invertedFunduleAfterQuickInfo_test.go b/internal/fourslash/tests/gen/invertedFunduleAfterQuickInfo_test.go new file mode 100644 index 0000000000..92e8271aa4 --- /dev/null +++ b/internal/fourslash/tests/gen/invertedFunduleAfterQuickInfo_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInvertedFunduleAfterQuickInfo(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + module A { + var o; + } + function A(/**/x: number): void { } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyQuickInfoExists(t) + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/javascriptModules22_test.go b/internal/fourslash/tests/gen/javascriptModules22_test.go new file mode 100644 index 0000000000..7922f48cbe --- /dev/null +++ b/internal/fourslash/tests/gen/javascriptModules22_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavascriptModules22(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @module: commonjs +// @allowSyntheticDefaultImports: false +// @esModuleInterop: false +// @Filename: mod.js +function foo() { return {a: "hello, world"}; } +module.exports = foo(); +// @Filename: mod2.js +var x = {name: 'test'}; +(function createExport(obj){ + module.exports = { + "default": x, + "sausages": {eggs: 2} + }; +})(); +// @Filename: app.js +import {a} from "./mod" +import def, {sausages} from "./mod2" +a./**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "toString", + }, + }, + }) + f.Backspace(t, 2) + f.Insert(t, "def.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "name", + }, + }, + }) + f.Insert(t, "name;\nsausages.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "eggs", + }, + }, + }) + f.Insert(t, "eggs;") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/javascriptModules24_test.go b/internal/fourslash/tests/gen/javascriptModules24_test.go new file mode 100644 index 0000000000..00eec0b220 --- /dev/null +++ b/internal/fourslash/tests/gen/javascriptModules24_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavascriptModules24(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: mod.ts +function foo() { return 42; } +namespace foo { + export function bar (a: string) { return a; } +} +export = foo; +// @Filename: app.ts +import * as foo from "./mod" +foo/*1*/(); +foo.bar(/*2*/"test");` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyErrorExistsBeforeMarker(t, "1") + f.VerifyQuickInfoIs(t, "(alias) function foo(): number\n(alias) namespace foo\nimport foo", "") + f.GoToMarker(t, "2") + f.VerifySignatureHelp(t, fourslash.VerifySignatureHelpOptions{}) +} diff --git a/internal/fourslash/tests/gen/jsDocFunctionSignatures4_test.go b/internal/fourslash/tests/gen/jsDocFunctionSignatures4_test.go new file mode 100644 index 0000000000..27e1c9ed23 --- /dev/null +++ b/internal/fourslash/tests/gen/jsDocFunctionSignatures4_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJsDocFunctionSignatures4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js +/** @param {function ({OwnerID:string,AwayID:string}):void} x + * @param {function (string):void} y */ +function fn(x, y) { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/jsconfig_test.go b/internal/fourslash/tests/gen/jsconfig_test.go new file mode 100644 index 0000000000..dc1931fb00 --- /dev/null +++ b/internal/fourslash/tests/gen/jsconfig_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJsconfig(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.js +function f(/**/x) { +} +// @Filename: /jsconfig.json +{ + "compilerOptions": { + "checkJs": true, + "noImplicitAny": true + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "/a.js") + f.VerifyErrorExistsAfterMarker(t, "") +} diff --git a/internal/fourslash/tests/gen/jsdocDeprecated_suggestion8_test.go b/internal/fourslash/tests/gen/jsdocDeprecated_suggestion8_test.go new file mode 100644 index 0000000000..1e4587395c --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocDeprecated_suggestion8_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJsdocDeprecated_suggestion8(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: first.ts +/** @deprecated */ +export declare function tap(next: null): void; +export declare function tap(next: T): T; +// @Filename: second.ts +import { tap } from './first'; +tap` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "second.ts") + f.VerifyNoErrors(t) + f.VerifySuggestionDiagnostics(t, nil) +} diff --git a/internal/fourslash/tests/gen/jsdocDeprecated_suggestion9_test.go b/internal/fourslash/tests/gen/jsdocDeprecated_suggestion9_test.go new file mode 100644 index 0000000000..f62f7e814a --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocDeprecated_suggestion9_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJsdocDeprecated_suggestion9(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: first.ts +export class logger { } +// @Filename: second.ts +import { logger } from './first'; +new logger()` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "second.ts") + f.VerifyNoErrors(t) + f.VerifySuggestionDiagnostics(t, nil) +} diff --git a/internal/fourslash/tests/gen/memberConstructorEdits_test.go b/internal/fourslash/tests/gen/memberConstructorEdits_test.go new file mode 100644 index 0000000000..cf22a865da --- /dev/null +++ b/internal/fourslash/tests/gen/memberConstructorEdits_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMemberConstructorEdits(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` module M { + export class A { + constructor(a: string) {} + public m(n: number) { + return 0; + } + public n() { + return this.m(0); + } + } + export class B extends A { + constructor(a: string) { + super(a); + } + /*1*/ + } + var a = new A("s"); + var b = new B("s"); + }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.Insert(t, "public m(n: number) { return 0; }") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/memberOverloadEdits_test.go b/internal/fourslash/tests/gen/memberOverloadEdits_test.go new file mode 100644 index 0000000000..4a77053331 --- /dev/null +++ b/internal/fourslash/tests/gen/memberOverloadEdits_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMemberOverloadEdits(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export class A { + public m(n: number) { + return 0; + } + public n() { + return this.m(0); + } + } + export class B extends A { /*1*/ } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.Insert(t, "public m(n: number) { return 0; }") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/missingMethodAfterEditAfterImport_test.go b/internal/fourslash/tests/gen/missingMethodAfterEditAfterImport_test.go new file mode 100644 index 0000000000..654b66a608 --- /dev/null +++ b/internal/fourslash/tests/gen/missingMethodAfterEditAfterImport_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMissingMethodAfterEditAfterImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `namespace foo { + export namespace bar { namespace baz { export class boo { } } } +} + +import f = /*foo*/foo; + +/*delete*/var x;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "foo", "namespace foo", "") + f.GoToMarker(t, "delete") + f.DeleteAtCaret(t, 6) + f.VerifyQuickInfoAt(t, "foo", "namespace foo", "") +} diff --git a/internal/fourslash/tests/gen/multiModuleClodule_test.go b/internal/fourslash/tests/gen/multiModuleClodule_test.go new file mode 100644 index 0000000000..a5bc4093c4 --- /dev/null +++ b/internal/fourslash/tests/gen/multiModuleClodule_test.go @@ -0,0 +1,91 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMultiModuleClodule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + constructor(x: number) { } + foo() { } + bar() { } + static boo() { } +} + +module C { + export var x = 1; + var y = 2; +} +module C { + export function foo() { } + function baz() { return ''; } +} + +var c = new C/*1*/(C./*2*/x); +c./*3*/foo = C./*4*/foo;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "C", + }, + }, + }) + f.VerifyCompletions(t, []string{"2", "4"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: CompletionFunctionMembersPlus( + []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "boo", + SortText: PtrTo(string(ls.SortTextLocalDeclarationPriority)), + }, + &lsproto.CompletionItem{ + Label: "foo", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "prototype", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "x", + SortText: PtrTo(string(ls.SortTextLocationPriority)), + }, + }), + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "bar", + "foo", + }, + }, + }) + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/multiModuleFundule_test.go b/internal/fourslash/tests/gen/multiModuleFundule_test.go new file mode 100644 index 0000000000..a33d80d7d4 --- /dev/null +++ b/internal/fourslash/tests/gen/multiModuleFundule_test.go @@ -0,0 +1,72 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMultiModuleFundule(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function C(x: number) { } + +module C { + export var x = 1; +} +module C { + export function foo() { } +} + +var /*2*/r = C(/*1*/ +var /*4*/r2 = new C(/*3*/ // using void returning function as constructor +var r3 = C./*5*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "C", + }, + }, + }) + f.Insert(t, "C.x);") + f.VerifyQuickInfoAt(t, "2", "var r: void", "") + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "C", + }, + }, + }) + f.Insert(t, "C.x);") + f.VerifyQuickInfoAt(t, "4", "var r2: any", "") + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &DefaultCommitCharacters, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "x", + "foo", + }, + }, + }) + f.Insert(t, "x;") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/ngProxy4_test.go b/internal/fourslash/tests/gen/ngProxy4_test.go new file mode 100644 index 0000000000..102bf6520c --- /dev/null +++ b/internal/fourslash/tests/gen/ngProxy4_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestNgProxy4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: tsconfig.json +{ + "compilerOptions": { + "plugins": [ + { "name": "diagnostic-adder" } + ] + }, + "files": ["a.ts"] +} +// @Filename: a.ts +let x = [1, 2]; +x/**/ +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction1_test.go b/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction1_test.go new file mode 100644 index 0000000000..03b6a186e8 --- /dev/null +++ b/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction1_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestNoErrorsAfterCompletionsRequestWithinGenericFunction1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +declare function func(arg: T): void; +func({ foo: 1, bar/*1*/: 1 });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyCompletions(t, nil, nil) + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction2_test.go b/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction2_test.go new file mode 100644 index 0000000000..c911a7a91e --- /dev/null +++ b/internal/fourslash/tests/gen/noErrorsAfterCompletionsRequestWithinGenericFunction2_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestNoErrorsAfterCompletionsRequestWithinGenericFunction2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +// repro from #50818#issuecomment-1278324638 + +declare function func(arg: T): void; +func({ foo: 1, bar/*1*/: 1 });` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "2") + f.VerifyCompletions(t, nil, nil) + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/nodeModulesFileEditStillAllowsResolutionsToWork_test.go b/internal/fourslash/tests/gen/nodeModulesFileEditStillAllowsResolutionsToWork_test.go new file mode 100644 index 0000000000..0788bcd8a2 --- /dev/null +++ b/internal/fourslash/tests/gen/nodeModulesFileEditStillAllowsResolutionsToWork_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestNodeModulesFileEditStillAllowsResolutionsToWork(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /tsconfig.json +{ "compilerOptions": { "module": "nodenext", "strict": true } } +// @Filename: /package.json +{ "type": "module", "imports": { "#foo": "./foo.cjs" } } +// @Filename: /foo.cts +export const x = 1; +// @Filename: /index.ts +import * as mod from "#foo"; +/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "mod.x") + f.VerifyNoErrors(t) + f.VerifySuggestionDiagnostics(t, nil) +} diff --git a/internal/fourslash/tests/gen/nodeNextModuleKindCaching1_test.go b/internal/fourslash/tests/gen/nodeNextModuleKindCaching1_test.go new file mode 100644 index 0000000000..bc9265dbbf --- /dev/null +++ b/internal/fourslash/tests/gen/nodeNextModuleKindCaching1_test.go @@ -0,0 +1,46 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestNodeNextModuleKindCaching1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: tsconfig.json +{ + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "target": "ES2020", + "module": "NodeNext", + "strict": true + }, + "include": ["src\\**\\*.ts"] +} +// @Filename: package.json +{ + "type": "module", + "private": true +} +// @Filename: src/index.ts +// The line below should show a "Relative import paths need explicit file +// extensions..." error in VS Code, but it doesn't. The error is only picked up +// by ` + "`" + `tsc` + "`" + ` which seems to properly infer the module type. +import { helloWorld } from './example' +/**/ +helloWorld() +// @Filename: src/example.ts +export function helloWorld() { + console.log('Hello, world!') +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToMarker(t, "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/partialUnionPropertyCacheInconsistentErrors_test.go b/internal/fourslash/tests/gen/partialUnionPropertyCacheInconsistentErrors_test.go new file mode 100644 index 0000000000..652102c5d6 --- /dev/null +++ b/internal/fourslash/tests/gen/partialUnionPropertyCacheInconsistentErrors_test.go @@ -0,0 +1,55 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPartialUnionPropertyCacheInconsistentErrors(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +// @lib: esnext +interface ComponentOptions { + setup?: (props: Props) => void; + name?: string; +} + +interface FunctionalComponent

{ + (props: P): void; +} + +type ConcreteComponent = + | ComponentOptions + | FunctionalComponent; + +type Component = ConcreteComponent; + +type WithInstallPlugin = { _prefix?: string }; + + +/**/ +export function withInstall( + component: C | C[], + target?: T, +): string { + const componentWithInstall = (target ?? component) as T; + const components = Array.isArray(component) ? component : [component]; + + const { name } = components[0]; + if (name) { + return name; + } + + return ""; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "") + f.Insert(t, "type C = Component['name']") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/pasteLambdaOverModule_test.go b/internal/fourslash/tests/gen/pasteLambdaOverModule_test.go new file mode 100644 index 0000000000..1039765a49 --- /dev/null +++ b/internal/fourslash/tests/gen/pasteLambdaOverModule_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPasteLambdaOverModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Paste(t, "module B { }") + f.GoToBOF(t) + f.DeleteAtCaret(t, 12) + f.Insert(t, "var t = (public x) => { };") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/paste_test.go b/internal/fourslash/tests/gen/paste_test.go new file mode 100644 index 0000000000..5d94914927 --- /dev/null +++ b/internal/fourslash/tests/gen/paste_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPaste(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `fn(/**/);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Paste(t, "x,y,z") + f.VerifyCurrentLineContentIs(t, "fn(x, y, z);") +} diff --git a/internal/fourslash/tests/gen/quickInfoCloduleWithRecursiveReference_test.go b/internal/fourslash/tests/gen/quickInfoCloduleWithRecursiveReference_test.go new file mode 100644 index 0000000000..2b2f81b75c --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoCloduleWithRecursiveReference_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoCloduleWithRecursiveReference(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export class C { + foo() { } + } + export module C { + export var /**/C = M.C + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "", "var M.C.C: typeof M.C", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoGenericCombinators2_test.go b/internal/fourslash/tests/gen/quickInfoGenericCombinators2_test.go new file mode 100644 index 0000000000..eb305ba85b --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoGenericCombinators2_test.go @@ -0,0 +1,102 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoGenericCombinators2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Collection { + length: number; + add(x: T, y: U): void ; + remove(x: T, y: U): boolean; +} + +interface Combinators { + map(c: Collection, f: (x: T, y: U) => V): Collection; + map(c: Collection, f: (x: T, y: U) => any): Collection; +} + +class A { + foo(): T { return null; } +} + +class B { + foo(x: T): T { return null; } +} + +var c1: Collection; +var c2: Collection; +var c3: Collection, string>; +var c4: Collection; +var c5: Collection>; + +var _: Combinators; +// param help on open paren for arg 2 should show 'number' not T or 'any' +// x should be contextually typed to number +var rf1 = (x: number, y: string) => { return x.toFixed() }; +var rf2 = (x: Collection, y: string) => { return x.length }; +var rf3 = (x: number, y: A) => { return y.foo() }; + +var /*9*/r1a = _.map/*1c*/(c2, (/*1a*/x, /*1b*/y) => { return x.toFixed() }); +var /*10*/r1b = _.map(c2, rf1); + +var /*11*/r2a = _.map(c3, (/*2a*/x, /*2b*/y) => { return x.length }); +var /*12*/r2b = _.map(c3, rf2); + +var /*13*/r3a = _.map(c4, (/*3a*/x, /*3b*/y) => { return y.foo() }); +var /*14*/r3b = _.map(c4, rf3); + +var /*15*/r4a = _.map(c5, (/*4a*/x, /*4b*/y) => { return y.foo() }); + +var /*17*/r5a = _.map(c2, /*17error1*/(/*5a*/x, /*5b*/y) => { return x.toFixed() }/*17error2*/); +var rf1b = (x: number, y: string) => { return new Date() }; +var /*18*/r5b = _.map(c2, rf1b); + +var /*19*/r6a = _.map, string, Date>(c3, (/*6a*/x,/*6b*/y) => { return new Date(); }); +var rf2b = (x: Collection, y: string) => { return new Date(); }; +var /*20*/r6b = _.map, string, Date>(c3, rf2b); + +var /*21*/r7a = _.map(c4, (/*7a*/x,/*7b*/y) => { return y.foo() }); +var /*22*/r7b = _.map(c4, /*22error1*/rf3/*22error2*/); + +var /*23*/r8a = _.map(c5, (/*8a*/x,/*8b*/y) => { return y.foo() }); ` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "2a", "(parameter) x: Collection", "") + f.VerifyQuickInfoAt(t, "2b", "(parameter) y: string", "") + f.VerifyQuickInfoAt(t, "3a", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "3b", "(parameter) y: A", "") + f.VerifyQuickInfoAt(t, "4a", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "4b", "(parameter) y: B", "") + f.VerifyQuickInfoAt(t, "5a", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "5b", "(parameter) y: string", "") + f.VerifyQuickInfoAt(t, "6a", "(parameter) x: Collection", "") + f.VerifyQuickInfoAt(t, "6b", "(parameter) y: string", "") + f.VerifyQuickInfoAt(t, "7a", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "7b", "(parameter) y: A", "") + f.VerifyQuickInfoAt(t, "8a", "(parameter) x: number", "") + f.VerifyQuickInfoAt(t, "8b", "(parameter) y: any", "") + f.VerifyQuickInfoAt(t, "9", "var r1a: Collection", "") + f.VerifyQuickInfoAt(t, "10", "var r1b: Collection", "") + f.VerifyQuickInfoAt(t, "11", "var r2a: Collection, number>", "") + f.VerifyQuickInfoAt(t, "12", "var r2b: Collection, number>", "") + f.VerifyQuickInfoAt(t, "13", "var r3a: Collection", "") + f.VerifyQuickInfoAt(t, "14", "var r3b: Collection", "") + f.VerifyQuickInfoAt(t, "15", "var r4a: Collection", "") + f.VerifyQuickInfoAt(t, "17", "var r5a: Collection", "") + f.VerifyQuickInfoAt(t, "18", "var r5b: Collection", "") + f.VerifyQuickInfoAt(t, "19", "var r6a: Collection, Date>", "") + f.VerifyQuickInfoAt(t, "20", "var r6b: Collection, Date>", "") + f.VerifyQuickInfoAt(t, "21", "var r7a: Collection", "") + f.VerifyQuickInfoAt(t, "22", "var r7b: Collection", "") + f.VerifyQuickInfoAt(t, "23", "var r8a: Collection", "") + f.VerifyErrorExistsBetweenMarkers(t, "error1", "error2") + f.VerifyErrorExistsBetweenMarkers(t, "17error1", "17error2") + f.VerifyErrorExistsBetweenMarkers(t, "22error1", "22error2") +} diff --git a/internal/fourslash/tests/gen/quickInfoGenericTypeArgumentInference1_test.go b/internal/fourslash/tests/gen/quickInfoGenericTypeArgumentInference1_test.go new file mode 100644 index 0000000000..1c3a3772b4 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoGenericTypeArgumentInference1_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoGenericTypeArgumentInference1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Underscore { + export interface Iterator { + (value: T, index: any, list: any): U; + } + + export interface Static { + all(list: T[], iterator?: Iterator, context?: any): T; + identity(value: T): T; + } +} + +declare var _: Underscore.Static; +var /*1*/r = _./*11*/all([true, 1, null, 'yes'], x => !x); +var /*2*/r2 = _./*21*/all([true], _.identity); +var /*3*/r3 = _./*31*/all([], _.identity); +var /*4*/r4 = _./*41*/all([true], _.identity);` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "var r: string | number | boolean", "") + f.VerifyQuickInfoAt(t, "11", "(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean", "") + f.VerifyQuickInfoAt(t, "2", "var r2: boolean", "") + f.VerifyQuickInfoAt(t, "21", "(method) Underscore.Static.all(list: boolean[], iterator?: Underscore.Iterator, context?: any): boolean", "") + f.VerifyQuickInfoAt(t, "3", "var r3: any", "") + f.VerifyQuickInfoAt(t, "31", "(method) Underscore.Static.all(list: any[], iterator?: Underscore.Iterator, context?: any): any", "") + f.VerifyQuickInfoAt(t, "4", "var r4: any", "") + f.VerifyQuickInfoAt(t, "41", "(method) Underscore.Static.all(list: any[], iterator?: Underscore.Iterator, context?: any): any", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoInheritedLinkTag_test.go b/internal/fourslash/tests/gen/quickInfoInheritedLinkTag_test.go new file mode 100644 index 0000000000..75b606746b --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoInheritedLinkTag_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoInheritedLinkTag(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /** + * @deprecated Use {@link PerspectiveCamera#setFocalLength .setFocalLength()} and {@link PerspectiveCamera#filmGauge .filmGauge} instead. + */ + m() { } +} +export class D extends C { + m() { } // crashes here +} +new C().m/**/ // and here (with a different thing trying to access undefined)` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoJsdocEnum_test.go b/internal/fourslash/tests/gen/quickInfoJsdocEnum_test.go new file mode 100644 index 0000000000..a42ada8eec --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoJsdocEnum_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoJsdocEnum(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @noLib: true +// @Filename: /a.js +/** + * Doc + * @enum {number} + */ +const E = { + A: 0, +} + +/** @type {/*type*/E} */ +const x = /*value*/E.A;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyQuickInfoAt(t, "type", "type E = number", "Doc") + f.VerifyQuickInfoAt(t, "value", "const E: {\n A: number;\n}", "Doc") +} diff --git a/internal/fourslash/tests/gen/quickInfoLink2_test.go b/internal/fourslash/tests/gen/quickInfoLink2_test.go new file mode 100644 index 0000000000..271fe6d785 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoLink2_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoLink2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: quickInfoLink2.js +/** + * @typedef AdditionalWallabyConfig/**/ Additional valid Wallaby config properties + * that aren't defined in {@link IWallabyConfig}. + * @property {boolean} autoDetect + */` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoLink3_test.go b/internal/fourslash/tests/gen/quickInfoLink3_test.go new file mode 100644 index 0000000000..4e5e5d8283 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoLink3_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoLink3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /** + * {@link Foo} + * {@link Foo} + * {@link Foo>} + * {@link Foo<>} + * {@link Foo>} + * {@link Foo<} + */ + bar/**/(){} +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoLink4_test.go b/internal/fourslash/tests/gen/quickInfoLink4_test.go new file mode 100644 index 0000000000..fb1e7b55dc --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoLink4_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoLink4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type A = 1 | 2; + +switch (0 as A) { + /** {@link /**/A} */ + case 1: + case 2: + break; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoLinkCodePlain_test.go b/internal/fourslash/tests/gen/quickInfoLinkCodePlain_test.go new file mode 100644 index 0000000000..6a1b888e2d --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoLinkCodePlain_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoLinkCodePlain(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /** + * @deprecated Use {@linkplain PerspectiveCamera#setFocalLength .setFocalLength()} and {@linkcode PerspectiveCamera#filmGauge .filmGauge} instead. + */ + m() { } +} +new C().m/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoMeaning_test.go b/internal/fourslash/tests/gen/quickInfoMeaning_test.go new file mode 100644 index 0000000000..10f772a0bc --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoMeaning_test.go @@ -0,0 +1,96 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoMeaning(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.d.ts +declare const [|/*foo_value_declaration*/foo: number|]; +[|declare module "foo_module" { + interface /*foo_type_declaration*/I { x: number; y: number } + export = I; +}|] +// @Filename: foo_user.ts +/// +[|import foo = require("foo_module");|] +const x = foo/*foo_value*/; +const i: foo/*foo_type*/ = { x: 1, y: 2 }; +// @Filename: bar.d.ts +[|declare interface /*bar_type_declaration*/bar { x: number; y: number }|] +[|declare module "bar_module" { + const /*bar_value_declaration*/x: number; + export = x; +}|] +// @Filename: bar_user.ts +/// +[|import bar = require("bar_module");|] +const x = bar/*bar_value*/; +const i: bar/*bar_type*/ = { x: 1, y: 2 };` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyWorkspaceSymbol(t, []*fourslash.VerifyWorkspaceSymbolCase{ + { + Pattern: "foo", + Preferences: nil, + Exact: PtrTo([]*lsproto.SymbolInformation{ + { + Name: "foo", + Kind: lsproto.SymbolKindVariable, + Location: f.Ranges()[0].LSLocation(), + }, + { + Name: "foo", + Kind: lsproto.SymbolKindVariable, + Location: f.Ranges()[2].LSLocation(), + }, + { + Name: "foo_module", + Kind: lsproto.SymbolKindNamespace, + Location: f.Ranges()[1].LSLocation(), + }, + }), + }, + }) + f.GoToMarker(t, "foo_value") + f.VerifyQuickInfoIs(t, "const foo: number", "") + f.GoToMarker(t, "foo_type") + f.VerifyQuickInfoIs(t, "(alias) interface foo\nimport foo = require(\"foo_module\")", "") + f.VerifyWorkspaceSymbol(t, []*fourslash.VerifyWorkspaceSymbolCase{ + { + Pattern: "bar", + Preferences: nil, + Exact: PtrTo([]*lsproto.SymbolInformation{ + { + Name: "bar", + Kind: lsproto.SymbolKindInterface, + Location: f.Ranges()[3].LSLocation(), + }, + { + Name: "bar", + Kind: lsproto.SymbolKindVariable, + Location: f.Ranges()[5].LSLocation(), + }, + { + Name: "bar_module", + Kind: lsproto.SymbolKindNamespace, + Location: f.Ranges()[4].LSLocation(), + }, + }), + }, + }) + f.GoToMarker(t, "bar_value") + f.VerifyQuickInfoIs(t, "(alias) const bar: number\nimport bar = require(\"bar_module\")", "") + f.GoToMarker(t, "bar_type") + f.VerifyQuickInfoIs(t, "interface bar", "") + f.VerifyBaselineGoToDefinition(t, false, "foo_value", "foo_type", "bar_value", "bar_type") +} diff --git a/internal/fourslash/tests/gen/quickInfoOnMergedInterfacesWithIncrementalEdits_test.go b/internal/fourslash/tests/gen/quickInfoOnMergedInterfacesWithIncrementalEdits_test.go new file mode 100644 index 0000000000..56cd35707a --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoOnMergedInterfacesWithIncrementalEdits_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoOnMergedInterfacesWithIncrementalEdits(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module MM { + interface B { + foo: number; + } + interface B { + bar: string; + } + var b: B; + var r3 = b.foo; // number + var r/*2*/4 = b.b/*1*/ar; // string +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.VerifyQuickInfoIs(t, "(property) B.bar: string", "") + f.DeleteAtCaret(t, 1) + f.Insert(t, "z") + f.VerifyQuickInfoIs(t, "any", "") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.Backspace(t, 1) + f.Insert(t, "a") + f.VerifyQuickInfoIs(t, "(property) B.bar: string", "") + f.GoToMarker(t, "2") + f.VerifyQuickInfoIs(t, "var r4: string", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoOnMergedModule_test.go b/internal/fourslash/tests/gen/quickInfoOnMergedModule_test.go new file mode 100644 index 0000000000..70d63f2233 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoOnMergedModule_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoOnMergedModule(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M2 { + export interface A { + foo: string; + } + var a: A; + var r = a.foo + a.bar; +} +module M2 { + export interface A { + bar: number; + } + var a: A; + var r = a.fo/*1*/o + a.bar; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyQuickInfoAt(t, "1", "(property) M2.A.foo: string", "") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoThrowsTag_test.go b/internal/fourslash/tests/gen/quickInfoThrowsTag_test.go new file mode 100644 index 0000000000..6d0308bb58 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoThrowsTag_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoThrowsTag(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class E extends Error {} + +/** + * @throws {E} + */ +function f1() {} + +/** + * @throws {E} description + */ +function f2() {} + +/** + * @throws description + */ +function f3() {} +f1/*1*/() +f2/*2*/() +f3/*3*/()` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineHover(t) +} diff --git a/internal/fourslash/tests/gen/quickInfoUntypedModuleImport_test.go b/internal/fourslash/tests/gen/quickInfoUntypedModuleImport_test.go new file mode 100644 index 0000000000..06090861c3 --- /dev/null +++ b/internal/fourslash/tests/gen/quickInfoUntypedModuleImport_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestQuickInfoUntypedModuleImport(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: node_modules/foo/index.js + /*index*/{} +// @Filename: a.ts +import /*foo*/foo from /*fooModule*/"foo"; +/*fooCall*/foo();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToFile(t, "a.ts") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) + f.GoToMarker(t, "fooModule") + f.VerifyQuickInfoIs(t, "", "") + f.GoToMarker(t, "foo") + f.VerifyQuickInfoIs(t, "import foo", "") + f.VerifyBaselineFindAllReferences(t, "foo", "fooModule", "fooCall") + f.VerifyBaselineGoToDefinition(t, false, "fooModule", "foo") +} diff --git a/internal/fourslash/tests/gen/referencesForAmbients2_test.go b/internal/fourslash/tests/gen/referencesForAmbients2_test.go new file mode 100644 index 0000000000..ddaf852623 --- /dev/null +++ b/internal/fourslash/tests/gen/referencesForAmbients2_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestReferencesForAmbients2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /defA.ts +declare module "a" { + /*1*/export type /*2*/T = number; +} +// @Filename: /defB.ts +declare module "b" { + export import a = require("a"); + export const x: a./*3*/T; +} +// @Filename: /defC.ts +declare module "c" { + import b = require("b"); + const x: b.a./*4*/T; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/removeDeclareFunctionExports_test.go b/internal/fourslash/tests/gen/removeDeclareFunctionExports_test.go new file mode 100644 index 0000000000..211954119e --- /dev/null +++ b/internal/fourslash/tests/gen/removeDeclareFunctionExports_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveDeclareFunctionExports(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare module M { + function RegExp2(pattern: string): RegExp2; + export function RegExp2(pattern: string, flags: string): RegExp2; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToBOF(t) + f.DeleteAtCaret(t, 8) +} diff --git a/internal/fourslash/tests/gen/removeDeclareInModule_test.go b/internal/fourslash/tests/gen/removeDeclareInModule_test.go new file mode 100644 index 0000000000..615f7566ad --- /dev/null +++ b/internal/fourslash/tests/gen/removeDeclareInModule_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveDeclareInModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/export module Foo { + function a(): void {} +} + +Foo.a();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 7) + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/removeDeclareKeyword_test.go b/internal/fourslash/tests/gen/removeDeclareKeyword_test.go new file mode 100644 index 0000000000..20e6b22f7b --- /dev/null +++ b/internal/fourslash/tests/gen/removeDeclareKeyword_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveDeclareKeyword(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/declare var y; +var x = new y;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 7) +} diff --git a/internal/fourslash/tests/gen/removeDeclareParamTypeAnnotation_test.go b/internal/fourslash/tests/gen/removeDeclareParamTypeAnnotation_test.go new file mode 100644 index 0000000000..f596130d09 --- /dev/null +++ b/internal/fourslash/tests/gen/removeDeclareParamTypeAnnotation_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveDeclareParamTypeAnnotation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare class T { } +declare function parseInt(/**/s:T):T; +parseInt('2');` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 3) +} diff --git a/internal/fourslash/tests/gen/removeDuplicateIdentifier_test.go b/internal/fourslash/tests/gen/removeDuplicateIdentifier_test.go new file mode 100644 index 0000000000..d90a471ca5 --- /dev/null +++ b/internal/fourslash/tests/gen/removeDuplicateIdentifier_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveDuplicateIdentifier(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class foo{} +function foo() { return null; }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToBOF(t) + f.DeleteAtCaret(t, 11) +} diff --git a/internal/fourslash/tests/gen/removeExportedClassFromReopenedModule_test.go b/internal/fourslash/tests/gen/removeExportedClassFromReopenedModule_test.go new file mode 100644 index 0000000000..9b7c5cc0fe --- /dev/null +++ b/internal/fourslash/tests/gen/removeExportedClassFromReopenedModule_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveExportedClassFromReopenedModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module multiM { } + +module multiM { + /*1*/export class c { } +} +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.DeleteAtCaret(t, 18) + f.GoToEOF(t) + f.Insert(t, "new multiM.c();") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/removeInterfaceExtendsClause_test.go b/internal/fourslash/tests/gen/removeInterfaceExtendsClause_test.go new file mode 100644 index 0000000000..077296c58f --- /dev/null +++ b/internal/fourslash/tests/gen/removeInterfaceExtendsClause_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveInterfaceExtendsClause(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface IFoo { } +interface Array /**/extends IFoo { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 15) +} diff --git a/internal/fourslash/tests/gen/removeInterfaceUsedAsGenericTypeArgument_test.go b/internal/fourslash/tests/gen/removeInterfaceUsedAsGenericTypeArgument_test.go new file mode 100644 index 0000000000..8950a720a3 --- /dev/null +++ b/internal/fourslash/tests/gen/removeInterfaceUsedAsGenericTypeArgument_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveInterfaceUsedAsGenericTypeArgument(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/interface A { a: string; } +interface G { } +var v1: G;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 26) +} diff --git a/internal/fourslash/tests/gen/removeParameterBetweenCommentAndParameter_test.go b/internal/fourslash/tests/gen/removeParameterBetweenCommentAndParameter_test.go new file mode 100644 index 0000000000..3e689adccf --- /dev/null +++ b/internal/fourslash/tests/gen/removeParameterBetweenCommentAndParameter_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveParameterBetweenCommentAndParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function fn(/* comment! */ /**/a: number, c) { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 10) +} diff --git a/internal/fourslash/tests/gen/removeVarFromModuleWithReopenedEnums_test.go b/internal/fourslash/tests/gen/removeVarFromModuleWithReopenedEnums_test.go new file mode 100644 index 0000000000..390d8d5644 --- /dev/null +++ b/internal/fourslash/tests/gen/removeVarFromModuleWithReopenedEnums_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRemoveVarFromModuleWithReopenedEnums(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module A { + /**/var o; +} +enum A { +} +enum A { +} +module A { + var p; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.DeleteAtCaret(t, 6) +} diff --git a/internal/fourslash/tests/gen/renameDestructuringAssignmentInForOf_test.go b/internal/fourslash/tests/gen/renameDestructuringAssignmentInForOf_test.go new file mode 100644 index 0000000000..5831771829 --- /dev/null +++ b/internal/fourslash/tests/gen/renameDestructuringAssignmentInForOf_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameDestructuringAssignmentInForOf(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + [|[|{| "contextRangeIndex": 0 |}property1|]: number;|] + property2: string; +} +var elems: I[]; + +var [|[|{| "contextRangeIndex": 2 |}property1|]: number|], p2: number; +for ([|{ [|{| "contextRangeIndex": 4 |}property1|] } of elems|]) { + [|property1|]++; +} +for ([|{ [|{| "contextRangeIndex": 7 |}property1|]: p2 } of elems|]) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[8], f.Ranges()[3], f.Ranges()[5], f.Ranges()[6]) +} diff --git a/internal/fourslash/tests/gen/renameDestructuringAssignmentInFor_test.go b/internal/fourslash/tests/gen/renameDestructuringAssignmentInFor_test.go new file mode 100644 index 0000000000..966be93db8 --- /dev/null +++ b/internal/fourslash/tests/gen/renameDestructuringAssignmentInFor_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameDestructuringAssignmentInFor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + [|[|{| "contextRangeIndex": 0 |}property1|]: number;|] + property2: string; +} +var elems: I[]; + +var p2: number, [|[|{| "contextRangeIndex": 2 |}property1|]: number|]; +for ([|{ [|{| "contextRangeIndex": 4 |}property1|] } = elems[0]|]; p2 < 100; p2++) { + p2 = [|property1|]++; +} +for ([|{ [|{| "contextRangeIndex": 7 |}property1|]: p2 } = elems[0]|]; p2 < 100; p2++) { +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[8], f.Ranges()[3], f.Ranges()[5], f.Ranges()[6]) +} diff --git a/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor2_test.go b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor2_test.go new file mode 100644 index 0000000000..1e3abb4ff3 --- /dev/null +++ b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor2_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameDestructuringAssignmentNestedInFor2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface MultiRobot { + name: string; + skills: { + [|[|{| "contextRangeIndex": 0 |}primary|]: string;|] + secondary: string; + }; +} +let multiRobot: MultiRobot, [|[|{| "contextRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number; +for ([|{ skills: { [|{| "contextRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) { + primaryA; +} +for ([|{ skills: { [|{| "contextRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) { + [|primary|]; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[5], f.Ranges()[3], f.Ranges()[7], f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInForOf_test.go b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInForOf_test.go new file mode 100644 index 0000000000..e7cfdc7524 --- /dev/null +++ b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInForOf_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameDestructuringAssignmentNestedInForOf(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface MultiRobot { + name: string; + skills: { + [|[|{| "contextRangeIndex": 0 |}primary|]: string;|] + secondary: string; + }; +} +let multiRobots: MultiRobot[]; +let [|[|{| "contextRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string; +for ([|{ skills: { [|{| "contextRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) { + primaryA; +} +for ([|{ skills: { [|{| "contextRangeIndex": 6 |}primary|], secondary } } of multiRobots|]) { + [|primary|]; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[5], f.Ranges()[3], f.Ranges()[7], f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor_test.go b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor_test.go new file mode 100644 index 0000000000..ee635339fe --- /dev/null +++ b/internal/fourslash/tests/gen/renameDestructuringAssignmentNestedInFor_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameDestructuringAssignmentNestedInFor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface MultiRobot { + name: string; + skills: { + [|[|{| "contextRangeIndex": 0 |}primary|]: string;|] + secondary: string; + }; +} +let multiRobot: MultiRobot, [|[|{| "contextRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number; +for ([|{ skills: { [|{| "contextRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) { + primaryA; +} +for ([|{ skills: { [|{| "contextRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) { + [|primary|]; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[5], f.Ranges()[3], f.Ranges()[7], f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/renameImportOfExportEquals2_test.go b/internal/fourslash/tests/gen/renameImportOfExportEquals2_test.go new file mode 100644 index 0000000000..881b0a70e6 --- /dev/null +++ b/internal/fourslash/tests/gen/renameImportOfExportEquals2_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameImportOfExportEquals2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `[|declare namespace /*N*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}N|] { + export var x: number; +}|] +declare module "mod" { + [|export = [|{| "contextRangeIndex": 2 |}N|];|] +} +declare module "a" { + [|import * as /*O*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}O|] from "mod";|] + [|export { [|{| "contextRangeIndex": 6 |}O|] as /*P*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}P|] };|] // Renaming N here would rename +} +declare module "b" { + [|import { [|{| "contextRangeIndex": 9 |}P|] as /*Q*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 9 |}Q|] } from "a";|] + export const y: typeof [|Q|].x; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "N", "O", "P", "Q") + f.VerifyBaselineRenameAtRangesWithText(t, nil /*preferences*/, "N", "O", "P", "Q") +} diff --git a/internal/fourslash/tests/gen/renameImportOfReExport_test.go b/internal/fourslash/tests/gen/renameImportOfReExport_test.go new file mode 100644 index 0000000000..7cc5d959d4 --- /dev/null +++ b/internal/fourslash/tests/gen/renameImportOfReExport_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameImportOfReExport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +declare module "a" { + [|export class /*1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}C|] {}|] +} +declare module "b" { + [|export { /*2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}C|] } from "a";|] +} +declare module "c" { + [|import { /*3*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}C|] } from "b";|] + export function f(c: [|C|]): void; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[5], f.Ranges()[6]) +} diff --git a/internal/fourslash/tests/gen/renameModuleToVar_test.go b/internal/fourslash/tests/gen/renameModuleToVar_test.go new file mode 100644 index 0000000000..1668252ab5 --- /dev/null +++ b/internal/fourslash/tests/gen/renameModuleToVar_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRenameModuleToVar(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface IMod { + y: number; +} +declare module/**/ X: IMod;// { +// export var y: numb; +var y: number; +module Y { + var z = y + 5; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Backspace(t, 6) + f.Insert(t, "var") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go b/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go new file mode 100644 index 0000000000..59f69fcaeb --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingAfterArrayLiteral_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingAfterArrayLiteral(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `[1,2]/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "[1, 2];") +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go new file mode 100644 index 0000000000..2547f73d34 --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAComment_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingInsideAComment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` ///**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " //;") +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go new file mode 100644 index 0000000000..3d3cd23429 --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingInsideAStringLiteral_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingInsideAStringLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var x = "string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " var x = \"string;") +} diff --git a/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go new file mode 100644 index 0000000000..cc6eeac13b --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormattingNestedStatements_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormattingNestedStatements(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) +if (true)/*parentOutsideBlock*/ +if (true) { +if (true)/*directParent*/ +var x = 0/*innermost*/ +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "innermost") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, " var x = 0;") + f.GoToMarker(t, "directParent") + f.VerifyCurrentLineContentIs(t, " if (true)") + f.GoToMarker(t, "parentOutsideBlock") + f.VerifyCurrentLineContentIs(t, "if (true)") +} diff --git a/internal/fourslash/tests/gen/semicolonFormatting_test.go b/internal/fourslash/tests/gen/semicolonFormatting_test.go new file mode 100644 index 0000000000..c472d2cf19 --- /dev/null +++ b/internal/fourslash/tests/gen/semicolonFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSemicolonFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/function of1 (b:{r:{c:number` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "function of1(b: { r: { c: number;") +} diff --git a/internal/fourslash/tests/gen/signatureHelpCallExpressionJs_test.go b/internal/fourslash/tests/gen/signatureHelpCallExpressionJs_test.go new file mode 100644 index 0000000000..01bca912ac --- /dev/null +++ b/internal/fourslash/tests/gen/signatureHelpCallExpressionJs_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSignatureHelpCallExpressionJs(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @allowJs: true +// @Filename: main.js +function allOptional() { arguments; } +allOptional(/*1*/); +allOptional(1, 2, 3); +function someOptional(x, y) { arguments; } +someOptional(/*2*/); +someOptional(1, 2, 3); +someOptional(); // no error here; x and y are optional in JS` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.GoToMarker(t, "1") + f.VerifySignatureHelp(t, fourslash.VerifySignatureHelpOptions{Text: "allOptional(...args: any[]): void", ParameterCount: 1, ParameterName: "args", ParameterSpan: "...args: any[]", IsVariadic: true, IsVariadicSet: true}) + f.GoToMarker(t, "2") + f.VerifySignatureHelp(t, fourslash.VerifySignatureHelpOptions{Text: "someOptional(x: any, y: any, ...args: any[]): void", ParameterCount: 3, ParameterName: "x", ParameterSpan: "x: any", IsVariadic: true, IsVariadicSet: true}) +} diff --git a/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go b/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go new file mode 100644 index 0000000000..ac0c6248df --- /dev/null +++ b/internal/fourslash/tests/gen/singleLineTypeLiteralFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSingleLineTypeLiteralFormatting(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function of1(b: { r: { c: number/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "function of1(b: { r: { c: number;") +} diff --git a/internal/fourslash/tests/gen/spaceAfterConstructor_test.go b/internal/fourslash/tests/gen/spaceAfterConstructor_test.go new file mode 100644 index 0000000000..0da9ec77bd --- /dev/null +++ b/internal/fourslash/tests/gen/spaceAfterConstructor_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSpaceAfterConstructor(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class myController { + private _processId; + constructor (processId: number) {/*1*/ + this._processId = processId; + }/*2*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "2") + f.Insert(t, "}") + f.GoToMarker(t, "1") + f.VerifyCurrentLineContentIs(t, " constructor(processId: number) {") +} diff --git a/internal/fourslash/tests/gen/squiggleIllegalClassExtension_test.go b/internal/fourslash/tests/gen/squiggleIllegalClassExtension_test.go new file mode 100644 index 0000000000..89f3253490 --- /dev/null +++ b/internal/fourslash/tests/gen/squiggleIllegalClassExtension_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSquiggleIllegalClassExtension(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo extends /*1*/Bar/*2*/ { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/squiggleIllegalSubclassOverride_test.go b/internal/fourslash/tests/gen/squiggleIllegalSubclassOverride_test.go new file mode 100644 index 0000000000..876f502950 --- /dev/null +++ b/internal/fourslash/tests/gen/squiggleIllegalSubclassOverride_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSquiggleIllegalSubclassOverride(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + public x: number; +} + +class Bar extends Foo { + public /*1*/x/*2*/: string = 'hi'; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyErrorExistsBetweenMarkers(t, "1", "2") + f.VerifyNumberOfErrorsInCurrentFile(t, 1) +} diff --git a/internal/fourslash/tests/gen/superInDerivedTypeOfGenericWithStatics_test.go b/internal/fourslash/tests/gen/superInDerivedTypeOfGenericWithStatics_test.go new file mode 100644 index 0000000000..cf4e1977bc --- /dev/null +++ b/internal/fourslash/tests/gen/superInDerivedTypeOfGenericWithStatics_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestSuperInDerivedTypeOfGenericWithStatics(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export class C { + static foo(): C { + return null; + } + } +} +class D extends M.C { + constructor() { + /**/ // was an error appearing on super in editing scenarios + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "super();") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go b/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go new file mode 100644 index 0000000000..240e910340 --- /dev/null +++ b/internal/fourslash/tests/gen/tabbingAfterNewlineInsertedBeforeWhile_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTabbingAfterNewlineInsertedBeforeWhile(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function foo() { + /**/while (true) { } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.InsertLine(t, "") + f.VerifyCurrentLineContentIs(t, " while (true) { }") +} diff --git a/internal/fourslash/tests/gen/toggleDuplicateFunctionDeclaration_test.go b/internal/fourslash/tests/gen/toggleDuplicateFunctionDeclaration_test.go new file mode 100644 index 0000000000..4b959db797 --- /dev/null +++ b/internal/fourslash/tests/gen/toggleDuplicateFunctionDeclaration_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestToggleDuplicateFunctionDeclaration(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class D { } +D();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToBOF(t) + f.Insert(t, "declare function D();") + f.GoToBOF(t) + f.DeleteAtCaret(t, 21) +} diff --git a/internal/fourslash/tests/gen/transitiveExportImports2_test.go b/internal/fourslash/tests/gen/transitiveExportImports2_test.go new file mode 100644 index 0000000000..2ae00e6049 --- /dev/null +++ b/internal/fourslash/tests/gen/transitiveExportImports2_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTransitiveExportImports2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +[|namespace /*A*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}A|] { + export const x = 0; +}|] +// @Filename: b.ts +[|export import /*B*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}B|] = [|A|];|] +[|B|].x; +// @Filename: c.ts +[|import { /*C*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}B|] } from "./b";|]` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "A", "B", "C") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[4]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[3], f.Ranges()[5]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[7]) +} diff --git a/internal/fourslash/tests/gen/transitiveExportImports3_test.go b/internal/fourslash/tests/gen/transitiveExportImports3_test.go new file mode 100644 index 0000000000..c1934958db --- /dev/null +++ b/internal/fourslash/tests/gen/transitiveExportImports3_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTransitiveExportImports3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +[|export function /*f*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}f|]() {}|] +// @Filename: b.ts +[|export { [|{| "contextRangeIndex": 2 |}f|] as /*g0*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}g|] } from "./a";|] +[|import { /*f2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 5 |}f|] } from "./a";|] +[|import { /*g1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 7 |}g|] } from "./b";|]` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "f", "g0", "g1", "f2") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[6]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[4]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/transitiveExportImports_test.go b/internal/fourslash/tests/gen/transitiveExportImports_test.go new file mode 100644 index 0000000000..05d87afdd0 --- /dev/null +++ b/internal/fourslash/tests/gen/transitiveExportImports_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTransitiveExportImports(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +[|class /*1*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}A|] { +}|] +[|export = [|{| "contextRangeIndex": 2 |}A|];|] +// @Filename: b.ts +[|export import /*2*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}b|] = require('./a');|] +// @Filename: c.ts +[|import /*3*/[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}b|] = require('./b');|] +var a = new /*4*/[|b|]./**/[|b|]();` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyQuickInfoExists(t) + f.VerifyNoErrors(t) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[1], f.Ranges()[3]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[5], f.Ranges()[9]) + f.VerifyBaselineRename(t, nil /*preferences*/, f.Ranges()[7], f.Ranges()[8]) +} diff --git a/internal/fourslash/tests/gen/tripleSlashReferenceResolutionMode_test.go b/internal/fourslash/tests/gen/tripleSlashReferenceResolutionMode_test.go new file mode 100644 index 0000000000..55ea634ccc --- /dev/null +++ b/internal/fourslash/tests/gen/tripleSlashReferenceResolutionMode_test.go @@ -0,0 +1,37 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTripleSlashReferenceResolutionMode(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/tsconfig.json + { "compilerOptions": { "module": "nodenext", "declaration": true, "strict": true, "outDir": "out" }, "files": ["./index.ts"] } +// @Filename: /home/src/workspaces/project/package.json + { "private": true, "type": "commonjs" } +// @Filename: /home/src/workspaces/project/node_modules/pkg/package.json +{ "name": "pkg", "version": "0.0.1", "exports": { "require": "./require.cjs", "default": "./import.js" }, "type": "module" } +// @Filename: /home/src/workspaces/project/node_modules/pkg/require.d.cts +export {}; +export interface PkgRequireInterface { member: any; } +declare global { const pkgRequireGlobal: PkgRequireInterface; } +// @Filename: /home/src/workspaces/project/node_modules/pkg/import.d.ts +export {}; +export interface PkgImportInterface { field: any; } +declare global { const pkgImportGlobal: PkgImportInterface; } +// @Filename: /home/src/workspaces/project/index.ts +/// +pkgImportGlobal; +export {};` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.MarkTestAsStradaServer() + f.GoToFile(t, "/home/src/workspaces/project/index.ts") + f.VerifyNumberOfErrorsInCurrentFile(t, 0) +} diff --git a/internal/fourslash/tests/gen/tsxGoToDefinitionClassInDifferentFile_test.go b/internal/fourslash/tests/gen/tsxGoToDefinitionClassInDifferentFile_test.go new file mode 100644 index 0000000000..733b328719 --- /dev/null +++ b/internal/fourslash/tests/gen/tsxGoToDefinitionClassInDifferentFile_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTsxGoToDefinitionClassInDifferentFile(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @jsx: preserve +// @Filename: C.tsx +export default class /*def*/C {} +// @Filename: a.tsx +import C from "./C"; +const foo = ;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineGoToDefinition(t, false, "use") +} diff --git a/internal/fourslash/tests/gen/tsxRename4_test.go b/internal/fourslash/tests/gen/tsxRename4_test.go new file mode 100644 index 0000000000..e45310dc54 --- /dev/null +++ b/internal/fourslash/tests/gen/tsxRename4_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTsxRename4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @jsx: preserve +//@Filename: file.tsx +declare module JSX { + interface Element {} + interface IntrinsicElements { + div: {}; + } +} +[|class [|{| "contextRangeIndex": 0 |}MyClass|] {}|] + +[|<[|{| "contextRangeIndex": 2 |}MyClass|]>|]; +[|<[|{| "contextRangeIndex": 5 |}MyClass|]/>|]; + +[|<[|{| "contextRangeIndex": 7 |}div|]> |]` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) + f.VerifyBaselineRenameAtRangesWithText(t, nil /*preferences*/, "MyClass", "div") +} diff --git a/internal/fourslash/tests/gen/typeCheckAfterResolve_test.go b/internal/fourslash/tests/gen/typeCheckAfterResolve_test.go new file mode 100644 index 0000000000..8ba2ec0cef --- /dev/null +++ b/internal/fourslash/tests/gen/typeCheckAfterResolve_test.go @@ -0,0 +1,28 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTypeCheckAfterResolve(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*start*/class Point implements /*IPointRef*/IPoint { + getDist() { + ssss; + } +}/*end*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToEOF(t) + f.InsertLine(t, "") + f.VerifyQuickInfoAt(t, "IPointRef", "any", "") + f.VerifyErrorExistsAfterMarker(t, "IPointRef") + f.GoToEOF(t) + f.InsertLine(t, "") + f.VerifyErrorExistsAfterMarker(t, "IPointRef") +} diff --git a/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go b/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go new file mode 100644 index 0000000000..5a0a5c5c78 --- /dev/null +++ b/internal/fourslash/tests/gen/unclosedStringLiteralAutoformating_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUnclosedStringLiteralAutoformating(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = /*1*/"asd/*2*/ +class Foo { + /**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, "}") + f.VerifyCurrentLineContentIs(t, "}") +} diff --git a/internal/fourslash/tests/gen/underscoreTypings02_test.go b/internal/fourslash/tests/gen/underscoreTypings02_test.go new file mode 100644 index 0000000000..425cf2f74c --- /dev/null +++ b/internal/fourslash/tests/gen/underscoreTypings02_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUnderscoreTypings02(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: CommonJS +interface Dictionary { + [x: string]: T; +} +export interface ChainedObject { + functions: ChainedArray; + omit(): ChainedObject; + clone(): ChainedObject; +} +interface ChainedDictionary extends ChainedObject> { + foldl(): ChainedObject; + clone(): ChainedDictionary; +} +export interface ChainedArray extends ChainedObject> { + groupBy(): ChainedDictionary; + groupBy(propertyName): ChainedDictionary; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToPosition(t, 0) + f.VerifyNumberOfErrorsInCurrentFile(t, 2) +} diff --git a/internal/fourslash/tests/gen/unreachableStatementNodeReuse_test.go b/internal/fourslash/tests/gen/unreachableStatementNodeReuse_test.go new file mode 100644 index 0000000000..86a1e43f7b --- /dev/null +++ b/internal/fourslash/tests/gen/unreachableStatementNodeReuse_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUnreachableStatementNodeReuse(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function test() { + return/*a*/abc(); + return; +} +function abc() { }` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNumberOfErrorsInCurrentFile(t, 1) + f.GoToMarker(t, "a") + f.Insert(t, " ") + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/unusedVariableInClass5_test.go b/internal/fourslash/tests/gen/unusedVariableInClass5_test.go new file mode 100644 index 0000000000..5bd5a1dc82 --- /dev/null +++ b/internal/fourslash/tests/gen/unusedVariableInClass5_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUnusedVariableInClass5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noUnusedLocals: true +// @target: esnext +declare class greeter { + #private; + private name; +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyNoErrors(t) +} diff --git a/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go new file mode 100644 index 0000000000..ef66218b49 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceBeforeReturnTypeFormatting_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceBeforeReturnTypeFormatting(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x: () => string/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.Insert(t, ";") + f.VerifyCurrentLineContentIs(t, "var x: () => string;") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go new file mode 100644 index 0000000000..85cb8edd72 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming2_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let noSubTemplate = ` + "`" + `/* /*1*/` + "`" + `; +let templateHead = ` + "`" + `/* /*2*/${1 + 2}` + "`" + `; +let templateMiddle = ` + "`" + `/* ${1 + 2 /*3*/}` + "`" + `; +let templateTail = ` + "`" + `/* ${1 + 2} /*4*/` + "`" + `;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.GoToMarker(t, "2") + f.Insert(t, "\n") + f.GoToMarker(t, "3") + f.Insert(t, "\n") + f.GoToMarker(t, "4") + f.Insert(t, "\n") + f.VerifyCurrentFileContentIs(t, "let noSubTemplate = `/* \n`;\nlet templateHead = `/* \n${1 + 2}`;\nlet templateMiddle = `/* ${1 + 2\n }`;\nlet templateTail = `/* ${1 + 2} \n`;") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go new file mode 100644 index 0000000000..14bd4a74c4 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming3_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let t = "foo \ +bar \ +"/*1*/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, ";") + f.VerifyCurrentFileContentIs(t, "let t = \"foo \\\nbar \\ \n\";") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go new file mode 100644 index 0000000000..5e4699b533 --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming4_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var re = /\w+ /*1*//;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "1") + f.Insert(t, "\n") + f.VerifyCurrentFileContentIs(t, "var re = /\\w+\n /;") +} diff --git a/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go b/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go new file mode 100644 index 0000000000..80b298370c --- /dev/null +++ b/internal/fourslash/tests/gen/whiteSpaceTrimming_test.go @@ -0,0 +1,22 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestWhiteSpaceTrimming(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if (true) { + // + /*err*/}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "err") + f.Insert(t, "\n") + f.VerifyCurrentFileContentIs(t, "if (true) { \n // \n\n}") +} diff --git a/testdata/baselines/reference/fourslash/documentSymbols/deleteClassWithEnumPresent.baseline b/testdata/baselines/reference/fourslash/documentSymbols/deleteClassWithEnumPresent.baseline new file mode 100644 index 0000000000..7d97b07184 --- /dev/null +++ b/testdata/baselines/reference/fourslash/documentSymbols/deleteClassWithEnumPresent.baseline @@ -0,0 +1,10 @@ +// === Document Symbols === +// === /deleteClassWithEnumPresent.ts === +// <|enum [|{| name: Foo, kind: Enum |}Foo|] { <|[|{| name: a, kind: EnumMember |}a|]|>, <|[|{| name: b, kind: EnumMember |}b|]|>, <|[|{| name: c, kind: EnumMember |}c|]|> }|> +// + +// === Details === +(Enum) Foo + (EnumMember) a + (EnumMember) b + (EnumMember) c diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsExportAsNamespace.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsExportAsNamespace.baseline.jsonc new file mode 100644 index 0000000000..af8207ceac --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsExportAsNamespace.baseline.jsonc @@ -0,0 +1,36 @@ +// === findAllReferences === +// === /b.ts === +// import { [|f|] } from "a"; + +// === /c.ts === +// A.[|f|](); + +// === /node_modules/a/index.d.ts === +// export function /*FIND ALL REFS*/[|f|](): void; +// export as namespace A; + + + +// === findAllReferences === +// === /b.ts === +// import { /*FIND ALL REFS*/[|f|] } from "a"; + +// === /c.ts === +// A.[|f|](); + +// === /node_modules/a/index.d.ts === +// export function [|f|](): void; +// export as namespace A; + + + +// === findAllReferences === +// === /b.ts === +// import { [|f|] } from "a"; + +// === /c.ts === +// A./*FIND ALL REFS*/[|f|](); + +// === /node_modules/a/index.d.ts === +// export function [|f|](): void; +// export as namespace A; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport08.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport08.baseline.jsonc new file mode 100644 index 0000000000..3b568a570d --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport08.baseline.jsonc @@ -0,0 +1,8 @@ +// === findAllReferences === +// === /findAllRefsForDefaultExport08.ts === +// --- (line: 4) skipped --- +// +// var y = new DefaultExportedClass; +// +// namespace /*FIND ALL REFS*/[|DefaultExportedClass|] { +// } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.baseline.jsonc new file mode 100644 index 0000000000..666b50c409 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.baseline.jsonc @@ -0,0 +1,49 @@ +// === findAllReferences === +// === /export.ts === +// const /*FIND ALL REFS*/[|foo|] = 1; +// export = [|foo|]; + +// === /re-export-dep.ts === +// import [|fooDefault|] from "./re-export"; + +// === /re-export.ts === +// export { [|default|] } from "./export"; + + + +// === findAllReferences === +// === /export.ts === +// const [|foo|] = 1; +// export = /*FIND ALL REFS*/[|foo|]; + +// === /re-export-dep.ts === +// import [|fooDefault|] from "./re-export"; + +// === /re-export.ts === +// export { [|default|] } from "./export"; + + + +// === findAllReferences === +// === /export.ts === +// const [|foo|] = 1; +// export = [|foo|]; + +// === /re-export-dep.ts === +// import [|fooDefault|] from "./re-export"; + +// === /re-export.ts === +// export { /*FIND ALL REFS*/[|default|] } from "./export"; + + + +// === findAllReferences === +// === /export.ts === +// const [|foo|] = 1; +// export = [|foo|]; + +// === /re-export-dep.ts === +// import /*FIND ALL REFS*/[|fooDefault|] from "./re-export"; + +// === /re-export.ts === +// export { [|default|] } from "./export"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForModuleGlobal.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForModuleGlobal.baseline.jsonc new file mode 100644 index 0000000000..cdad54c704 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsForModuleGlobal.baseline.jsonc @@ -0,0 +1,5 @@ +// === findAllReferences === +// === /b.ts === +// /// +// import { x } from "/*FIND ALL REFS*/foo"; +// declare module "[|foo|]" {} \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsGlobalModuleAugmentation.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsGlobalModuleAugmentation.baseline.jsonc new file mode 100644 index 0000000000..a9ba8fd038 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsGlobalModuleAugmentation.baseline.jsonc @@ -0,0 +1,33 @@ +// === findAllReferences === +// === /a.ts === +// export {}; +// declare global { +// /*FIND ALL REFS*/function [|f|](): void; +// } + +// === /b.ts === +// [|f|](); + + + +// === findAllReferences === +// === /a.ts === +// export {}; +// declare global { +// function /*FIND ALL REFS*/[|f|](): void; +// } + +// === /b.ts === +// [|f|](); + + + +// === findAllReferences === +// === /a.ts === +// export {}; +// declare global { +// function [|f|](): void; +// } + +// === /b.ts === +// /*FIND ALL REFS*/[|f|](); \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportDefault.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportDefault.baseline.jsonc new file mode 100644 index 0000000000..e87ec96ce3 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportDefault.baseline.jsonc @@ -0,0 +1,10 @@ +// === findAllReferences === +// === /b.ts === +// import [|bar|] from "./f"; +// [|bar|](1, 2); + +// === /f.ts === +// export { [|foo|] as [|default|] }; +// function /*FIND ALL REFS*/[|foo|](a: number, b: number) { +// return a + b; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportEqualsJsonFile.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportEqualsJsonFile.baseline.jsonc new file mode 100644 index 0000000000..196ae39120 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportEqualsJsonFile.baseline.jsonc @@ -0,0 +1,59 @@ +// === findAllReferences === +// === /a.ts === +// import /*FIND ALL REFS*/[|j|] = require("./j.json"); +// [|j|]; + + + +// === findAllReferences === +// === /a.ts === +// import [|j|] = require("./j.json"); +// /*FIND ALL REFS*/[|j|]; + + + +// === findAllReferences === +// === /a.ts === +// import j = require("/*FIND ALL REFS*/[|./j.json|]"); +// j; + +// === /b.js === +// const j = require("[|./j.json|]"); +// j; + +// === /j.json === +// [|{ "x": 0 }|] + + + +// === findAllReferences === +// === /a.ts === +// import j = require("[|./j.json|]"); +// j; + +// === /b.js === +// const j = require("/*FIND ALL REFS*/[|./j.json|]"); +// j; + +// === /j.json === +// [|{ "x": 0 }|] + + + +// === findAllReferences === +// === /b.js === +// const /*FIND ALL REFS*/[|j|] = require("./j.json"); +// [|j|]; + + + +// === findAllReferences === +// === /b.js === +// const [|j|] = require("./j.json"); +// /*FIND ALL REFS*/[|j|]; + + + +// === findAllReferences === +// === /j.json === +// /*FIND ALL REFS*/{ "x": 0 } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportNamed.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportNamed.baseline.jsonc new file mode 100644 index 0000000000..7c5bd7e1a0 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportNamed.baseline.jsonc @@ -0,0 +1,8 @@ +// === findAllReferences === +// === /b.ts === +// import x = require("./f"); +// x.[|foo|](1, 2); + +// === /f.ts === +// export { [|foo|] as [|foo|] } +// function /*FIND ALL REFS*/[|foo|](a: number, b: number) { } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportStarOfExportEquals.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportStarOfExportEquals.baseline.jsonc new file mode 100644 index 0000000000..635c80ede7 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsImportStarOfExportEquals.baseline.jsonc @@ -0,0 +1,133 @@ +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import [|a|] from "a"; +// [|a|](); +// [|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function /*FIND ALL REFS*/[|a|](): void; +// declare namespace [|a|] { +// export const x: number; +// } +// export = [|a|]; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import [|a|] from "a"; +// [|a|](); +// [|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|a|](): void; +// declare namespace /*FIND ALL REFS*/[|a|] { +// export const x: number; +// } +// export = [|a|]; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import [|a|] from "a"; +// [|a|](); +// [|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|a|](): void; +// declare namespace [|a|] { +// export const x: number; +// } +// export = /*FIND ALL REFS*/[|a|]; + + + +// === findAllReferences === +// === /b.ts === +// import /*FIND ALL REFS*/[|b|] from "a"; +// [|b|](); +// [|b|].x; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// /*FIND ALL REFS*/[|b|](); +// [|b|].x; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import /*FIND ALL REFS*/[|a|] from "a"; +// [|a|](); +// [|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|a|](): void; +// declare namespace [|a|] { +// export const x: number; +// } +// export = [|a|]; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import [|a|] from "a"; +// /*FIND ALL REFS*/[|a|](); +// [|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|a|](): void; +// declare namespace [|a|] { +// export const x: number; +// } +// export = [|a|]; + + + +// === findAllReferences === +// === /b.ts === +// import [|b|] from "a"; +// [|b|](); +// [|b|].x; + +// === /c.ts === +// import [|a|] from "a"; +// [|a|](); +// /*FIND ALL REFS*/[|a|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|a|](): void; +// declare namespace [|a|] { +// export const x: number; +// } +// export = [|a|]; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsModuleAugmentation.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsModuleAugmentation.baseline.jsonc new file mode 100644 index 0000000000..3951cc01dc --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsModuleAugmentation.baseline.jsonc @@ -0,0 +1,33 @@ +// === findAllReferences === +// === /a.ts === +// import * as foo from "foo"; +// declare module "foo" { +// export const x: [|T|]; +// } + +// === /node_modules/foo/index.d.ts === +// /*FIND ALL REFS*/export type [|T|] = number; + + + +// === findAllReferences === +// === /a.ts === +// import * as foo from "foo"; +// declare module "foo" { +// export const x: [|T|]; +// } + +// === /node_modules/foo/index.d.ts === +// export type /*FIND ALL REFS*/[|T|] = number; + + + +// === findAllReferences === +// === /a.ts === +// import * as foo from "foo"; +// declare module "foo" { +// export const x: /*FIND ALL REFS*/[|T|]; +// } + +// === /node_modules/foo/index.d.ts === +// export type [|T|] = number; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor.baseline.jsonc new file mode 100644 index 0000000000..988a5f99e5 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor.baseline.jsonc @@ -0,0 +1,39 @@ +// === findAllReferences === +// === /findAllRefsOfConstructor.ts === +// class A { +// /*FIND ALL REFS*/[|constructor|](s: string) {} +// } +// class B extends A { } +// class C extends B { +// constructor() { +// [|super|](""); +// } +// } +// class D extends B { } +// class E implements A { } +// const a = new [|A|]("a"); +// const b = new [|B|]("b"); +// const c = new C(); +// const d = new [|D|]("d"); +// const e = new E(); + + + +// === findAllReferences === +// === /findAllRefsOfConstructor.ts === +// class A { +// constructor(s: string) {} +// } +// class B extends A { } +// class C extends B { +// /*FIND ALL REFS*/[|constructor|]() { +// super(""); +// } +// } +// class D extends B { } +// class E implements A { } +// const a = new A("a"); +// const b = new B("b"); +// const c = new [|C|](); +// const d = new D("d"); +// const e = new E(); \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor2.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor2.baseline.jsonc new file mode 100644 index 0000000000..6aa7d264ea --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor2.baseline.jsonc @@ -0,0 +1,57 @@ +// === findAllReferences === +// === /findAllRefsOfConstructor2.ts === +// class A { +// /*FIND ALL REFS*/[|constructor|](s: string) {} +// } +// class B extends A { +// constructor() { [|super|](""); } +// } +// class C extends B { +// constructor() { +// super(); +// } +// } +// class D extends B { } +// const a = new [|A|]("a"); +// const b = new B(); +// const c = new C(); +// const d = new D(); + + + +// === findAllReferences === +// === /findAllRefsOfConstructor2.ts === +// class A { +// constructor(s: string) {} +// } +// class B extends A { +// /*FIND ALL REFS*/[|constructor|]() { super(""); } +// } +// class C extends B { +// constructor() { +// [|super|](); +// } +// } +// class D extends B { } +// const a = new A("a"); +// const b = new [|B|](); +// const c = new C(); +// const d = new [|D|](); + + + +// === findAllReferences === +// === /findAllRefsOfConstructor2.ts === +// --- (line: 4) skipped --- +// constructor() { super(""); } +// } +// class C extends B { +// /*FIND ALL REFS*/[|constructor|]() { +// super(); +// } +// } +// class D extends B { } +// const a = new A("a"); +// const b = new B(); +// const c = new [|C|](); +// const d = new D(); \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor_multipleFiles.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor_multipleFiles.baseline.jsonc new file mode 100644 index 0000000000..8d1f4f8ead --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsOfConstructor_multipleFiles.baseline.jsonc @@ -0,0 +1,18 @@ +// === findAllReferences === +// === /a.ts === +// import { [|A|] as A1 } from "./f"; +// const a1 = new [|A1|]("a1"); +// export default class extends A1 { } +// export { [|B|] as [|B1|] } from "./f"; + +// === /b.ts === +// import B, { B1 } from "./a"; +// const d = new [|B|]("b"); +// const d1 = new [|B1|]("b1"); + +// === /f.ts === +// class A { +// /*FIND ALL REFS*/[|constructor|](s: string) {} +// } +// class B extends A { } +// export { [|A|], [|B|] }; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsPrefixSuffixPreference.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsPrefixSuffixPreference.baseline.jsonc new file mode 100644 index 0000000000..4909dd61cc --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsPrefixSuffixPreference.baseline.jsonc @@ -0,0 +1,106 @@ +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const /*FIND ALL REFS*/[|q|] = 1; +// export { [|q|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { [|q|] } from "./file1"; +// log([|q|] + 1); + + + +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const [|q|] = 1; +// export { /*FIND ALL REFS*/[|q|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { [|q|] } from "./file1"; +// log([|q|] + 1); + + + +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const [|q|] = 1; +// export { [|q|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { /*FIND ALL REFS*/[|q|] } from "./file1"; +// log([|q|] + 1); + + + +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const [|q|] = 1; +// export { [|q|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { [|q|] } from "./file1"; +// log(/*FIND ALL REFS*/[|q|] + 1); + + + +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { q }; +// const x = { +// /*FIND ALL REFS*/[|z|]: 'value' +// } +// const { [|z|] } = x; +// log(z); + + + +// === findAllReferences === +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { q }; +// const x = { +// [|z|]: 'value' +// } +// const { /*FIND ALL REFS*/[|z|] } = x; +// log([|z|]); + + + +// === findAllReferences === +// === /file1.ts === +// --- (line: 3) skipped --- +// const x = { +// z: 'value' +// } +// const { [|z|] } = x; +// log(/*FIND ALL REFS*/[|z|]); \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportLocal.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportLocal.baseline.jsonc new file mode 100644 index 0000000000..147c24f1ef --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportLocal.baseline.jsonc @@ -0,0 +1,93 @@ +// === findAllReferences === +// === /a.ts === +// var /*FIND ALL REFS*/[|x|]; +// export { [|x|] }; +// export { [|x|] as [|y|] }; + +// === /b.ts === +// import { [|x|], [|y|] } from "./a"; +// [|x|]; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var [|x|]; +// export { /*FIND ALL REFS*/[|x|] }; +// export { [|x|] as [|y|] }; + +// === /b.ts === +// import { [|x|], [|y|] } from "./a"; +// [|x|]; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var [|x|]; +// export { [|x|] }; +// export { /*FIND ALL REFS*/[|x|] as [|y|] }; + +// === /b.ts === +// import { [|x|], [|y|] } from "./a"; +// [|x|]; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var [|x|]; +// export { [|x|] }; +// export { [|x|] as [|y|] }; + +// === /b.ts === +// import { /*FIND ALL REFS*/[|x|], [|y|] } from "./a"; +// [|x|]; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var [|x|]; +// export { [|x|] }; +// export { [|x|] as [|y|] }; + +// === /b.ts === +// import { [|x|], [|y|] } from "./a"; +// /*FIND ALL REFS*/[|x|]; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var x; +// export { x }; +// export { x as /*FIND ALL REFS*/[|y|] }; + +// === /b.ts === +// import { x, [|y|] } from "./a"; +// x; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var x; +// export { x }; +// export { x as [|y|] }; + +// === /b.ts === +// import { x, /*FIND ALL REFS*/[|y|] } from "./a"; +// x; [|y|]; + + + +// === findAllReferences === +// === /a.ts === +// var x; +// export { x }; +// export { x as [|y|] }; + +// === /b.ts === +// import { x, [|y|] } from "./a"; +// x; /*FIND ALL REFS*/[|y|]; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc new file mode 100644 index 0000000000..690a325204 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc @@ -0,0 +1,72 @@ +// === findAllReferences === +// === /a.ts === +// export const /*FIND ALL REFS*/[|x|] = 0; + +// === /c.ts === +// export { x } from "./b"; +// import { [|x|] } from "./a"; +// [|x|]; + + + +// === findAllReferences === +// === /b.ts === +// export const /*FIND ALL REFS*/[|x|] = 0; + +// === /c.ts === +// export { [|x|] } from "./b"; +// import { x } from "./a"; +// x; + +// === /d.ts === +// import { [|x|] } from "./c"; + + + +// === findAllReferences === +// === /b.ts === +// export const [|x|] = 0; + +// === /c.ts === +// export { /*FIND ALL REFS*/[|x|] } from "./b"; +// import { x } from "./a"; +// x; + +// === /d.ts === +// import { [|x|] } from "./c"; + + + +// === findAllReferences === +// === /a.ts === +// export const [|x|] = 0; + +// === /c.ts === +// export { x } from "./b"; +// import { /*FIND ALL REFS*/[|x|] } from "./a"; +// [|x|]; + + + +// === findAllReferences === +// === /a.ts === +// export const [|x|] = 0; + +// === /c.ts === +// export { x } from "./b"; +// import { [|x|] } from "./a"; +// /*FIND ALL REFS*/[|x|]; + + + +// === findAllReferences === +// === /b.ts === +// export const [|x|] = 0; + +// === /c.ts === +// export { [|x|] } from "./b"; +// import { x } from "./a"; +// x; + +// === /d.ts === +// import { /*FIND ALL REFS*/[|x|] } from "./c"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStar.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStar.baseline.jsonc new file mode 100644 index 0000000000..37e4edbc06 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStar.baseline.jsonc @@ -0,0 +1,15 @@ +// === findAllReferences === +// === /a.ts === +// export function /*FIND ALL REFS*/[|foo|](): void {} + +// === /c.ts === +// import { [|foo|] } from "./b"; + + + +// === findAllReferences === +// === /a.ts === +// export function [|foo|](): void {} + +// === /c.ts === +// import { /*FIND ALL REFS*/[|foo|] } from "./b"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStarAs.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStarAs.baseline.jsonc new file mode 100644 index 0000000000..22a217bed3 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportStarAs.baseline.jsonc @@ -0,0 +1,47 @@ +// === findAllReferences === +// === /importing.ts === +// import { Leaf } from './exporting'; +// Leaf.[|hello|]() + +// === /leafModule.ts === +// export const /*FIND ALL REFS*/[|hello|] = () => 'Hello'; + + + +// === findAllReferences === +// === /importing.ts === +// import { Leaf } from './exporting'; +// Leaf./*FIND ALL REFS*/[|hello|]() + +// === /leafModule.ts === +// export const [|hello|] = () => 'Hello'; + + + +// === findAllReferences === +// === /exporting.ts === +// export * as /*FIND ALL REFS*/[|Leaf|] from './leafModule'; + +// === /importing.ts === +// import { [|Leaf|] } from './exporting'; +// [|Leaf|].hello() + + + +// === findAllReferences === +// === /exporting.ts === +// export * as [|Leaf|] from './leafModule'; + +// === /importing.ts === +// import { /*FIND ALL REFS*/[|Leaf|] } from './exporting'; +// [|Leaf|].hello() + + + +// === findAllReferences === +// === /exporting.ts === +// export * as [|Leaf|] from './leafModule'; + +// === /importing.ts === +// import { [|Leaf|] } from './exporting'; +// /*FIND ALL REFS*/[|Leaf|].hello() \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExports2.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExports2.baseline.jsonc new file mode 100644 index 0000000000..10f2a591c6 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExports2.baseline.jsonc @@ -0,0 +1,6 @@ +// === findAllReferences === +// === /a.ts === +// export function /*FIND ALL REFS*/[|foo|](): void {} + +// === /b.ts === +// import { [|foo|] as [|oof|] } from "./a"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportsUseInImportType.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportsUseInImportType.baseline.jsonc new file mode 100644 index 0000000000..a647cd1eb7 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsReExportsUseInImportType.baseline.jsonc @@ -0,0 +1,98 @@ +// === findAllReferences === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo.[|Full|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.[|Full|]; + +// === /foo/types/types.ts === +// export type /*FIND ALL REFS*/[|Full|] = { prop: string; }; + + + +// === findAllReferences === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo./*FIND ALL REFS*/[|Full|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.[|Full|]; + +// === /foo/types/types.ts === +// export type [|Full|] = { prop: string; }; + + + +// === findAllReferences === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo.[|Full|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo./*FIND ALL REFS*/[|Full|]; + +// === /foo/types/types.ts === +// export type [|Full|] = { prop: string; }; + + + +// === findAllReferences === +// === /app.ts === +// import { [|foo|] } from './foo/types'; +// export type fullType = [|foo|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|foo|].Full; + +// === /foo/types/index.ts === +// import * as /*FIND ALL REFS*/[|foo|] from './types'; +// export { [|foo|] }; + + + +// === findAllReferences === +// === /app.ts === +// import { [|foo|] } from './foo/types'; +// export type fullType = [|foo|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|foo|].Full; + +// === /foo/types/index.ts === +// import * as [|foo|] from './types'; +// export { /*FIND ALL REFS*/[|foo|] }; + + + +// === findAllReferences === +// === /app.ts === +// import { /*FIND ALL REFS*/[|foo|] } from './foo/types'; +// export type fullType = [|foo|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|foo|].Full; + +// === /foo/types/index.ts === +// import * as [|foo|] from './types'; +// export { [|foo|] }; + + + +// === findAllReferences === +// === /app.ts === +// import { [|foo|] } from './foo/types'; +// export type fullType = /*FIND ALL REFS*/[|foo|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|foo|].Full; + +// === /foo/types/index.ts === +// import * as [|foo|] from './types'; +// export { [|foo|] }; + + + +// === findAllReferences === +// === /app.ts === +// import { [|foo|] } from './foo/types'; +// export type fullType = [|foo|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types')./*FIND ALL REFS*/[|foo|].Full; + +// === /foo/types/index.ts === +// import * as [|foo|] from './types'; +// export { [|foo|] }; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsRenameImportWithSameName.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsRenameImportWithSameName.baseline.jsonc new file mode 100644 index 0000000000..35698023d7 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsRenameImportWithSameName.baseline.jsonc @@ -0,0 +1,31 @@ +// === findAllReferences === +// === /a.ts === +// export const /*FIND ALL REFS*/[|x|] = 0; + +// === /b.ts === +// import { [|x|] as [|x|] } from "./a"; +// [|x|]; + + + +// === findAllReferences === +// === /a.ts === +// export const [|x|] = 0; + +// === /b.ts === +// import { /*FIND ALL REFS*/[|x|] as [|x|] } from "./a"; +// [|x|]; + + + +// === findAllReferences === +// === /b.ts === +// import { x as /*FIND ALL REFS*/[|x|] } from "./a"; +// [|x|]; + + + +// === findAllReferences === +// === /b.ts === +// import { x as [|x|] } from "./a"; +// /*FIND ALL REFS*/[|x|]; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/referencesForAmbients2.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/referencesForAmbients2.baseline.jsonc new file mode 100644 index 0000000000..5cf89ccc72 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/referencesForAmbients2.baseline.jsonc @@ -0,0 +1,77 @@ +// === findAllReferences === +// === /defA.ts === +// declare module "a" { +// /*FIND ALL REFS*/export type [|T|] = number; +// } + +// === /defB.ts === +// declare module "b" { +// export import a = require("a"); +// export const x: a.[|T|]; +// } + +// === /defC.ts === +// declare module "c" { +// import b = require("b"); +// const x: b.a.[|T|]; +// } + + + +// === findAllReferences === +// === /defA.ts === +// declare module "a" { +// export type /*FIND ALL REFS*/[|T|] = number; +// } + +// === /defB.ts === +// declare module "b" { +// export import a = require("a"); +// export const x: a.[|T|]; +// } + +// === /defC.ts === +// declare module "c" { +// import b = require("b"); +// const x: b.a.[|T|]; +// } + + + +// === findAllReferences === +// === /defA.ts === +// declare module "a" { +// export type [|T|] = number; +// } + +// === /defB.ts === +// declare module "b" { +// export import a = require("a"); +// export const x: a./*FIND ALL REFS*/[|T|]; +// } + +// === /defC.ts === +// declare module "c" { +// import b = require("b"); +// const x: b.a.[|T|]; +// } + + + +// === findAllReferences === +// === /defA.ts === +// declare module "a" { +// export type [|T|] = number; +// } + +// === /defB.ts === +// declare module "b" { +// export import a = require("a"); +// export const x: a.[|T|]; +// } + +// === /defC.ts === +// declare module "c" { +// import b = require("b"); +// const x: b.a./*FIND ALL REFS*/[|T|]; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfExportEquals2.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfExportEquals2.baseline.jsonc new file mode 100644 index 0000000000..aeda0414e3 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfExportEquals2.baseline.jsonc @@ -0,0 +1,59 @@ +// === findAllReferences === +// === /renameImportOfExportEquals2.ts === +// declare namespace /*FIND ALL REFS*/[|N|] { +// export var x: number; +// } +// declare module "mod" { +// export = [|N|]; +// } +// declare module "a" { +// import * as [|O|] from "mod"; +// export { [|O|] as [|P|] }; // Renaming N here would rename +// } +// declare module "b" { +// import { [|P|] as [|Q|] } from "a"; +// export const y: typeof [|Q|].x; +// } + + + +// === findAllReferences === +// === /renameImportOfExportEquals2.ts === +// --- (line: 4) skipped --- +// export = N; +// } +// declare module "a" { +// import * as /*FIND ALL REFS*/[|O|] from "mod"; +// export { [|O|] as [|P|] }; // Renaming N here would rename +// } +// declare module "b" { +// import { [|P|] as [|Q|] } from "a"; +// export const y: typeof [|Q|].x; +// } + + + +// === findAllReferences === +// === /renameImportOfExportEquals2.ts === +// --- (line: 5) skipped --- +// } +// declare module "a" { +// import * as O from "mod"; +// export { O as /*FIND ALL REFS*/[|P|] }; // Renaming N here would rename +// } +// declare module "b" { +// import { [|P|] as [|Q|] } from "a"; +// export const y: typeof [|Q|].x; +// } + + + +// === findAllReferences === +// === /renameImportOfExportEquals2.ts === +// --- (line: 8) skipped --- +// export { O as P }; // Renaming N here would rename +// } +// declare module "b" { +// import { P as /*FIND ALL REFS*/[|Q|] } from "a"; +// export const y: typeof [|Q|].x; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfReExport.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfReExport.baseline.jsonc new file mode 100644 index 0000000000..001ff3c4f1 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/renameImportOfReExport.baseline.jsonc @@ -0,0 +1,42 @@ +// === findAllReferences === +// === /renameImportOfReExport.ts === +// declare module "a" { +// export class /*FIND ALL REFS*/[|C|] {} +// } +// declare module "b" { +// export { [|C|] } from "a"; +// } +// declare module "c" { +// import { [|C|] } from "b"; +// export function f(c: [|C|]): void; +// } + + + +// === findAllReferences === +// === /renameImportOfReExport.ts === +// declare module "a" { +// export class [|C|] {} +// } +// declare module "b" { +// export { /*FIND ALL REFS*/[|C|] } from "a"; +// } +// declare module "c" { +// import { [|C|] } from "b"; +// export function f(c: [|C|]): void; +// } + + + +// === findAllReferences === +// === /renameImportOfReExport.ts === +// declare module "a" { +// export class [|C|] {} +// } +// declare module "b" { +// export { [|C|] } from "a"; +// } +// declare module "c" { +// import { /*FIND ALL REFS*/[|C|] } from "b"; +// export function f(c: [|C|]): void; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports.baseline.jsonc new file mode 100644 index 0000000000..3e9dc9e1be --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports.baseline.jsonc @@ -0,0 +1,36 @@ +// === findAllReferences === +// === /a.ts === +// class /*FIND ALL REFS*/[|A|] { +// } +// export = [|A|]; + +// === /b.ts === +// export import [|b|] = require('./a'); + +// === /c.ts === +// import b = require('./b'); +// var a = new b.[|b|](); + + + +// === findAllReferences === +// === /b.ts === +// export import /*FIND ALL REFS*/[|b|] = require('./a'); + +// === /c.ts === +// import b = require('./b'); +// var a = new b.[|b|](); + + + +// === findAllReferences === +// === /c.ts === +// import /*FIND ALL REFS*/[|b|] = require('./b'); +// var a = new [|b|].b(); + + + +// === findAllReferences === +// === /c.ts === +// import [|b|] = require('./b'); +// var a = new /*FIND ALL REFS*/[|b|].b(); \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports2.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports2.baseline.jsonc new file mode 100644 index 0000000000..e1028fead3 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports2.baseline.jsonc @@ -0,0 +1,32 @@ +// === findAllReferences === +// === /a.ts === +// namespace /*FIND ALL REFS*/[|A|] { +// export const x = 0; +// } + +// === /b.ts === +// export import [|B|] = [|A|]; +// [|B|].x; + +// === /c.ts === +// import { [|B|] } from "./b"; + + + +// === findAllReferences === +// === /b.ts === +// export import /*FIND ALL REFS*/[|B|] = A; +// [|B|].x; + +// === /c.ts === +// import { [|B|] } from "./b"; + + + +// === findAllReferences === +// === /b.ts === +// export import [|B|] = A; +// [|B|].x; + +// === /c.ts === +// import { /*FIND ALL REFS*/[|B|] } from "./b"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports3.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports3.baseline.jsonc new file mode 100644 index 0000000000..0f9249e992 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/transitiveExportImports3.baseline.jsonc @@ -0,0 +1,35 @@ +// === findAllReferences === +// === /a.ts === +// export function /*FIND ALL REFS*/[|f|]() {} + +// === /b.ts === +// export { [|f|] as [|g|] } from "./a"; +// import { [|f|] } from "./a"; +// import { [|g|] } from "./b"; + + + +// === findAllReferences === +// === /b.ts === +// export { f as /*FIND ALL REFS*/[|g|] } from "./a"; +// import { f } from "./a"; +// import { [|g|] } from "./b"; + + + +// === findAllReferences === +// === /b.ts === +// export { f as [|g|] } from "./a"; +// import { f } from "./a"; +// import { /*FIND ALL REFS*/[|g|] } from "./b"; + + + +// === findAllReferences === +// === /a.ts === +// export function [|f|]() {} + +// === /b.ts === +// export { [|f|] as [|g|] } from "./a"; +// import { /*FIND ALL REFS*/[|f|] } from "./a"; +// import { [|g|] } from "./b"; \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoInheritedLinkTag.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoInheritedLinkTag.baseline new file mode 100644 index 0000000000..a09c2c3e21 --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoInheritedLinkTag.baseline @@ -0,0 +1,51 @@ +// === QuickInfo === +=== /quickInfoInheritedLinkTag.ts === +// export class C { +// /** +// * @deprecated Use {@link PerspectiveCamera#setFocalLength .setFocalLength()} and {@link PerspectiveCamera#filmGauge .filmGauge} instead. +// */ +// m() { } +// } +// export class D extends C { +// m() { } // crashes here +// } +// new C().m // and here (with a different thing trying to access undefined) +// ^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | (method) C.m(): void +// | ``` +// | +// | +// | *@deprecated* — Use PerspectiveCamera.setFocalLength .setFocalLength() and PerspectiveCamera.filmGauge .filmGauge instead. +// | +// | ---------------------------------------------------------------------- +[ + { + "marker": { + "Position": 258, + "LSPosition": { + "line": 9, + "character": 9 + }, + "Name": "", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\n(method) C.m(): void\n```\n\n\n*@deprecated* — Use PerspectiveCamera.setFocalLength .setFocalLength() and PerspectiveCamera.filmGauge .filmGauge instead.\n" + }, + "range": { + "start": { + "line": 9, + "character": 8 + }, + "end": { + "line": 9, + "character": 9 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink2.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink2.baseline new file mode 100644 index 0000000000..17e42879b2 --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink2.baseline @@ -0,0 +1,43 @@ +// === QuickInfo === +=== /quickInfoLink2.js === +// /** +// * @typedef AdditionalWallabyConfig Additional valid Wallaby config properties +// ^^^^^^^^^^^^^^^^^^^^^^^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | type AdditionalWallabyConfig = { autoDetect: boolean; } +// | ``` +// | +// | ---------------------------------------------------------------------- +// * that aren't defined in {@link IWallabyConfig}. +// * @property {boolean} autoDetect +// */ +[ + { + "marker": { + "Position": 39, + "LSPosition": { + "line": 1, + "character": 35 + }, + "Name": "", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\ntype AdditionalWallabyConfig = { autoDetect: boolean; }\n```\n" + }, + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 35 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink3.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink3.baseline new file mode 100644 index 0000000000..7c668735bc --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink3.baseline @@ -0,0 +1,54 @@ +// === QuickInfo === +=== /quickInfoLink3.ts === +// class Foo { +// /** +// * {@link Foo} +// * {@link Foo} +// * {@link Foo>} +// * {@link Foo<>} +// * {@link Foo>} +// * {@link Foo<} +// */ +// bar(){} +// ^^^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | (method) Foo.bar(): void +// | ``` +// | [Foo](file:///quickInfoLink3.ts#1,7-1,10) +// | [](file:///quickInfoLink3.ts#1,7-1,10) +// | [>](file:///quickInfoLink3.ts#1,7-1,10) +// | [<>](file:///quickInfoLink3.ts#1,7-1,10) +// | [>](file:///quickInfoLink3.ts#1,7-1,10) +// | [<](file:///quickInfoLink3.ts#1,7-1,10) +// | ---------------------------------------------------------------------- +// } +[ + { + "marker": { + "Position": 169, + "LSPosition": { + "line": 9, + "character": 7 + }, + "Name": "", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\n(method) Foo.bar(): void\n```\n[Foo](file:///quickInfoLink3.ts#1,7-1,10)\n[](file:///quickInfoLink3.ts#1,7-1,10)\n[>](file:///quickInfoLink3.ts#1,7-1,10)\n[<>](file:///quickInfoLink3.ts#1,7-1,10)\n[>](file:///quickInfoLink3.ts#1,7-1,10)\n[<](file:///quickInfoLink3.ts#1,7-1,10)" + }, + "range": { + "start": { + "line": 9, + "character": 4 + }, + "end": { + "line": 9, + "character": 7 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink4.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink4.baseline new file mode 100644 index 0000000000..8c18758a45 --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLink4.baseline @@ -0,0 +1,46 @@ +// === QuickInfo === +=== /quickInfoLink4.ts === +// type A = 1 | 2; +// +// switch (0 as A) { +// /** {@link A} */ +// ^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | type A = 1 | 2 +// | ``` +// | +// | ---------------------------------------------------------------------- +// case 1: +// case 2: +// break; +// } +[ + { + "marker": { + "Position": 47, + "LSPosition": { + "line": 3, + "character": 12 + }, + "Name": "", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\ntype A = 1 | 2\n```\n" + }, + "range": { + "start": { + "line": 3, + "character": 12 + }, + "end": { + "line": 3, + "character": 13 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoLinkCodePlain.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLinkCodePlain.baseline new file mode 100644 index 0000000000..516a1ae0f5 --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoLinkCodePlain.baseline @@ -0,0 +1,48 @@ +// === QuickInfo === +=== /quickInfoLinkCodePlain.ts === +// export class C { +// /** +// * @deprecated Use {@linkplain PerspectiveCamera#setFocalLength .setFocalLength()} and {@linkcode PerspectiveCamera#filmGauge .filmGauge} instead. +// */ +// m() { } +// } +// new C().m +// ^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | (method) C.m(): void +// | ``` +// | +// | +// | *@deprecated* — Use PerspectiveCamera.setFocalLength .setFocalLength() and `PerspectiveCamera.filmGauge .filmGauge` instead. +// | +// | ---------------------------------------------------------------------- +[ + { + "marker": { + "Position": 210, + "LSPosition": { + "line": 6, + "character": 9 + }, + "Name": "", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\n(method) C.m(): void\n```\n\n\n*@deprecated* — Use PerspectiveCamera.setFocalLength .setFocalLength() and `PerspectiveCamera.filmGauge .filmGauge` instead.\n" + }, + "range": { + "start": { + "line": 6, + "character": 8 + }, + "end": { + "line": 6, + "character": 9 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/quickInfo/quickInfoThrowsTag.baseline b/testdata/baselines/reference/fourslash/quickInfo/quickInfoThrowsTag.baseline new file mode 100644 index 0000000000..859eb7742f --- /dev/null +++ b/testdata/baselines/reference/fourslash/quickInfo/quickInfoThrowsTag.baseline @@ -0,0 +1,134 @@ +// === QuickInfo === +=== /quickInfoThrowsTag.ts === +// class E extends Error {} +// +// /** +// * @throws {E} +// */ +// function f1() {} +// +// /** +// * @throws {E} description +// */ +// function f2() {} +// +// /** +// * @throws description +// */ +// function f3() {} +// f1() +// ^^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | function f1(): void +// | ``` +// | +// | +// | *@throws* — {E} +// | +// | ---------------------------------------------------------------------- +// f2() +// ^^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | function f2(): void +// | ``` +// | +// | +// | *@throws* — {E} description +// | +// | ---------------------------------------------------------------------- +// f3() +// ^^ +// | ---------------------------------------------------------------------- +// | ```tsx +// | function f3(): void +// | ``` +// | +// | +// | *@throws* — description +// | +// | ---------------------------------------------------------------------- +[ + { + "marker": { + "Position": 170, + "LSPosition": { + "line": 16, + "character": 2 + }, + "Name": "1", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\nfunction f1(): void\n```\n\n\n*@throws* — {E}\n" + }, + "range": { + "start": { + "line": 16, + "character": 0 + }, + "end": { + "line": 16, + "character": 2 + } + } + } + }, + { + "marker": { + "Position": 175, + "LSPosition": { + "line": 17, + "character": 2 + }, + "Name": "2", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\nfunction f2(): void\n```\n\n\n*@throws* — {E} description\n" + }, + "range": { + "start": { + "line": 17, + "character": 0 + }, + "end": { + "line": 17, + "character": 2 + } + } + } + }, + { + "marker": { + "Position": 180, + "LSPosition": { + "line": 18, + "character": 2 + }, + "Name": "3", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```tsx\nfunction f3(): void\n```\n\n\n*@throws* — description\n" + }, + "range": { + "start": { + "line": 18, + "character": 0 + }, + "end": { + "line": 18, + "character": 2 + } + } + } + } +] \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc new file mode 100644 index 0000000000..37a62c7d6d --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc @@ -0,0 +1,90 @@ +// === findRenameLocations === +// === /c.ts === +// import [|aRENAME|] from "a"; +// [|aRENAME|](); +// [|aRENAME|].x; + +// === /node_modules/a/index.d.ts === +// declare function /*RENAME*/[|aRENAME|](): void; +// declare namespace [|aRENAME|] { +// export const x: number; +// } +// export = [|aRENAME|]; + + + +// === findRenameLocations === +// === /c.ts === +// import [|aRENAME|] from "a"; +// [|aRENAME|](); +// [|aRENAME|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|aRENAME|](): void; +// declare namespace /*RENAME*/[|aRENAME|] { +// export const x: number; +// } +// export = [|aRENAME|]; + + + +// === findRenameLocations === +// === /c.ts === +// import [|aRENAME|] from "a"; +// [|aRENAME|](); +// [|aRENAME|].x; + +// === /node_modules/a/index.d.ts === +// declare function [|aRENAME|](): void; +// declare namespace [|aRENAME|] { +// export const x: number; +// } +// export = /*RENAME*/[|aRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// import /*RENAME*/[|bRENAME|] from "a"; +// [|bRENAME|](); +// [|bRENAME|].x; + + + +// === findRenameLocations === +// === /b.ts === +// import [|bRENAME|] from "a"; +// /*RENAME*/[|bRENAME|](); +// [|bRENAME|].x; + + + +// === findRenameLocations === +// === /b.ts === +// import [|bRENAME|] from "a"; +// [|bRENAME|](); +// /*RENAME*/[|bRENAME|].x; + + + +// === findRenameLocations === +// === /c.ts === +// import /*RENAME*/[|aRENAME|] from "a"; +// [|aRENAME|](); +// [|aRENAME|].x; + + + +// === findRenameLocations === +// === /c.ts === +// import [|aRENAME|] from "a"; +// /*RENAME*/[|aRENAME|](); +// [|aRENAME|].x; + + + +// === findRenameLocations === +// === /c.ts === +// import [|aRENAME|] from "a"; +// [|aRENAME|](); +// /*RENAME*/[|aRENAME|].x; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc.diff new file mode 100644 index 0000000000..3d1ba797b8 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsImportStarOfExportEquals.baseline.jsonc.diff @@ -0,0 +1,58 @@ +--- old.findAllRefsImportStarOfExportEquals.baseline.jsonc ++++ new.findAllRefsImportStarOfExportEquals.baseline.jsonc +@@= skipped -0, +0 lines =@@ + // === findRenameLocations === ++// === /c.ts === ++// import [|aRENAME|] from "a"; ++// [|aRENAME|](); ++// [|aRENAME|].x; ++ + // === /node_modules/a/index.d.ts === + // declare function /*RENAME*/[|aRENAME|](): void; + // declare namespace [|aRENAME|] { +@@= skipped -5, +10 lines =@@ + // } + // export = [|aRENAME|]; + ++ ++ ++// === findRenameLocations === + // === /c.ts === + // import [|aRENAME|] from "a"; + // [|aRENAME|](); + // [|aRENAME|].x; + +- +- +-// === findRenameLocations === + // === /node_modules/a/index.d.ts === + // declare function [|aRENAME|](): void; + // declare namespace /*RENAME*/[|aRENAME|] { +@@= skipped -15, +15 lines =@@ + // } + // export = [|aRENAME|]; + ++ ++ ++// === findRenameLocations === + // === /c.ts === + // import [|aRENAME|] from "a"; + // [|aRENAME|](); + // [|aRENAME|].x; + +- +- +-// === findRenameLocations === + // === /node_modules/a/index.d.ts === + // declare function [|aRENAME|](): void; + // declare namespace [|aRENAME|] { + // export const x: number; + // } + // export = /*RENAME*/[|aRENAME|]; +- +-// === /c.ts === +-// import [|aRENAME|] from "a"; +-// [|aRENAME|](); +-// [|aRENAME|].x; + + diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc new file mode 100644 index 0000000000..5fe7d981bc --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc @@ -0,0 +1,189 @@ +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file1.ts === +// declare function log(s: string | number): void; +// const /*RENAME*/[|qRENAME|] = 1; +// export { [|qRENAME|] as q/*END SUFFIX*/ }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { [|qRENAME|] } from "./file1"; +// log([|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] } from "./file1"; +// log([|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { /*START PREFIX*/q as [|qRENAME|] } from "./file1"; +// log(/*RENAME*/[|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file1.ts === +// declare function log(s: string | number): void; +// const /*RENAME*/[|qRENAME|] = 1; +// export { [|qRENAME|] as q/*END SUFFIX*/ }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] }; +// const x = { +// z: 'value' +// } +// const { z } = x; +// log(z); + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { [|qRENAME|] } from "./file1"; +// log([|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] } from "./file1"; +// log([|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file2.ts === +// declare function log(s: string | number): void; +// import { /*START PREFIX*/q as [|qRENAME|] } from "./file1"; +// log(/*RENAME*/[|qRENAME|] + 1); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { q }; +// const x = { +// /*RENAME*/[|zRENAME|]: 'value' +// } +// const { [|zRENAME|]: z/*END SUFFIX*/ } = x; +// log(z); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file1.ts === +// --- (line: 3) skipped --- +// const x = { +// z: 'value' +// } +// const { /*START PREFIX*/z: /*RENAME*/[|zRENAME|] } = x; +// log([|zRENAME|]); + + + +// === findRenameLocations === +// @useAliasesForRename: true + +// === /file1.ts === +// --- (line: 3) skipped --- +// const x = { +// z: 'value' +// } +// const { /*START PREFIX*/z: [|zRENAME|] } = x; +// log(/*RENAME*/[|zRENAME|]); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file1.ts === +// declare function log(s: string | number): void; +// const q = 1; +// export { q }; +// const x = { +// /*RENAME*/[|zRENAME|]: 'value' +// } +// const { [|zRENAME|]: z/*END SUFFIX*/ } = x; +// log(z); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file1.ts === +// --- (line: 3) skipped --- +// const x = { +// z: 'value' +// } +// const { /*START PREFIX*/z: /*RENAME*/[|zRENAME|] } = x; +// log([|zRENAME|]); + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /file1.ts === +// --- (line: 3) skipped --- +// const x = { +// z: 'value' +// } +// const { /*START PREFIX*/z: [|zRENAME|] } = x; +// log(/*RENAME*/[|zRENAME|]); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc.diff new file mode 100644 index 0000000000..5bb6cfc6b2 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc.diff @@ -0,0 +1,189 @@ +--- old.findAllRefsPrefixSuffixPreference.baseline.jsonc ++++ new.findAllRefsPrefixSuffixPreference.baseline.jsonc +@@= skipped -58, +58 lines =@@ + // === /file1.ts === + // declare function log(s: string | number): void; + // const /*RENAME*/[|qRENAME|] = 1; +-// export { [|qRENAME|] }; +-// const x = { +-// z: 'value' +-// } +-// const { z } = x; +-// log(z); +- +-// === /file2.ts === +-// declare function log(s: string | number): void; +-// import { [|qRENAME|] } from "./file1"; +-// log([|qRENAME|] + 1); +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /file1.ts === +-// declare function log(s: string | number): void; +-// const [|qRENAME|] = 1; +-// export { /*RENAME*/[|qRENAME|] }; +-// const x = { +-// z: 'value' +-// } +-// const { z } = x; +-// log(z); +- +-// === /file2.ts === +-// declare function log(s: string | number): void; +-// import { [|qRENAME|] } from "./file1"; +-// log([|qRENAME|] + 1); +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /file2.ts === +-// declare function log(s: string | number): void; +-// import { /*RENAME*/[|qRENAME|] } from "./file1"; +-// log([|qRENAME|] + 1); +- +-// === /file1.ts === +-// declare function log(s: string | number): void; +-// const [|qRENAME|] = 1; +-// export { [|qRENAME|] }; +-// const x = { +-// z: 'value' +-// } +-// const { z } = x; +-// log(z); +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /file2.ts === +-// declare function log(s: string | number): void; +-// import { [|qRENAME|] } from "./file1"; ++// export { [|qRENAME|] as q/*END SUFFIX*/ }; ++// const x = { ++// z: 'value' ++// } ++// const { z } = x; ++// log(z); ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /file1.ts === ++// declare function log(s: string | number): void; ++// const q = 1; ++// export { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] }; ++// const x = { ++// z: 'value' ++// } ++// const { z } = x; ++// log(z); ++ ++// === /file2.ts === ++// declare function log(s: string | number): void; ++// import { [|qRENAME|] } from "./file1"; ++// log([|qRENAME|] + 1); ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /file2.ts === ++// declare function log(s: string | number): void; ++// import { /*START PREFIX*/q as /*RENAME*/[|qRENAME|] } from "./file1"; ++// log([|qRENAME|] + 1); ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /file2.ts === ++// declare function log(s: string | number): void; ++// import { /*START PREFIX*/q as [|qRENAME|] } from "./file1"; + // log(/*RENAME*/[|qRENAME|] + 1); + +-// === /file1.ts === +-// declare function log(s: string | number): void; +-// const [|qRENAME|] = 1; +-// export { [|qRENAME|] }; +-// const x = { +-// z: 'value' +-// } +-// const { z } = x; +-// log(z); +- + + + // === findRenameLocations === +@@= skipped -125, +100 lines =@@ + // const x = { + // /*RENAME*/[|zRENAME|]: 'value' + // } +-// const { [|zRENAME|] } = x; +-// log([|zRENAME|]); +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /file1.ts === +-// declare function log(s: string | number): void; +-// const q = 1; +-// export { q }; +-// const x = { +-// [|zRENAME|]: 'value' +-// } +-// const { /*RENAME*/[|zRENAME|] } = x; +-// log([|zRENAME|]); +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /file1.ts === +-// declare function log(s: string | number): void; +-// const q = 1; +-// export { q }; +-// const x = { +-// [|zRENAME|]: 'value' +-// } +-// const { [|zRENAME|] } = x; ++// const { [|zRENAME|]: z/*END SUFFIX*/ } = x; ++// log(z); ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /file1.ts === ++// --- (line: 3) skipped --- ++// const x = { ++// z: 'value' ++// } ++// const { /*START PREFIX*/z: /*RENAME*/[|zRENAME|] } = x; ++// log([|zRENAME|]); ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /file1.ts === ++// --- (line: 3) skipped --- ++// const x = { ++// z: 'value' ++// } ++// const { /*START PREFIX*/z: [|zRENAME|] } = x; + // log(/*RENAME*/[|zRENAME|]); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportLocal.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportLocal.baseline.jsonc new file mode 100644 index 0000000000..bbe1d07bb6 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportLocal.baseline.jsonc @@ -0,0 +1,65 @@ +// === findRenameLocations === +// === /a.ts === +// var /*RENAME*/[|xRENAME|]; +// export { [|xRENAME|] as x/*END SUFFIX*/ }; +// export { [|xRENAME|] as y }; + + + +// === findRenameLocations === +// === /a.ts === +// var [|xRENAME|]; +// export { [|xRENAME|] as x/*END SUFFIX*/ }; +// export { /*RENAME*/[|xRENAME|] as y }; + + + +// === findRenameLocations === +// === /a.ts === +// var x; +// export { /*START PREFIX*/x as /*RENAME*/[|xRENAME|] }; +// export { x as y }; + +// === /b.ts === +// import { [|xRENAME|], y } from "./a"; +// [|xRENAME|]; y; + + + +// === findRenameLocations === +// === /b.ts === +// import { /*START PREFIX*/x as /*RENAME*/[|xRENAME|], y } from "./a"; +// [|xRENAME|]; y; + + + +// === findRenameLocations === +// === /b.ts === +// import { /*START PREFIX*/x as [|xRENAME|], y } from "./a"; +// /*RENAME*/[|xRENAME|]; y; + + + +// === findRenameLocations === +// === /a.ts === +// var x; +// export { x }; +// export { x as /*RENAME*/[|yRENAME|] }; + +// === /b.ts === +// import { x, [|yRENAME|] } from "./a"; +// x; [|yRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// import { x, /*START PREFIX*/y as /*RENAME*/[|yRENAME|] } from "./a"; +// x; [|yRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// import { x, /*START PREFIX*/y as [|yRENAME|] } from "./a"; +// x; /*RENAME*/[|yRENAME|]; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc new file mode 100644 index 0000000000..5f0ba33832 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportRightNameWrongSymbol.baseline.jsonc @@ -0,0 +1,52 @@ +// === findRenameLocations === +// === /a.ts === +// export const /*RENAME*/[|xRENAME|] = 0; + +// === /c.ts === +// export { x } from "./b"; +// import { [|xRENAME|] } from "./a"; +// [|xRENAME|]; + + + +// === findRenameLocations === +// === /c.ts === +// export { x } from "./b"; +// import { /*START PREFIX*/x as /*RENAME*/[|xRENAME|] } from "./a"; +// [|xRENAME|]; + + + +// === findRenameLocations === +// === /c.ts === +// export { x } from "./b"; +// import { /*START PREFIX*/x as [|xRENAME|] } from "./a"; +// /*RENAME*/[|xRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// export const /*RENAME*/[|xRENAME|] = 0; + +// === /c.ts === +// export { [|xRENAME|] as x/*END SUFFIX*/ } from "./b"; +// import { x } from "./a"; +// x; + + + +// === findRenameLocations === +// === /c.ts === +// export { /*START PREFIX*/x as /*RENAME*/[|xRENAME|] } from "./b"; +// import { x } from "./a"; +// x; + +// === /d.ts === +// import { [|xRENAME|] } from "./c"; + + + +// === findRenameLocations === +// === /d.ts === +// import { /*START PREFIX*/x as /*RENAME*/[|xRENAME|] } from "./c"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc new file mode 100644 index 0000000000..5a8fb51b70 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc @@ -0,0 +1,145 @@ +// === findRenameLocations === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo.[|FullRENAME|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.[|FullRENAME|]; + +// === /foo/types/types.ts === +// export type /*RENAME*/[|FullRENAME|] = { prop: string; }; + + + +// === findRenameLocations === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo./*RENAME*/[|FullRENAME|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.[|FullRENAME|]; + +// === /foo/types/types.ts === +// export type [|FullRENAME|] = { prop: string; }; + + + +// === findRenameLocations === +// === /app.ts === +// import { foo } from './foo/types'; +// export type fullType = foo.[|FullRENAME|]; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo./*RENAME*/[|FullRENAME|]; + +// === /foo/types/types.ts === +// export type [|FullRENAME|] = { prop: string; }; + + + +// === findRenameLocations === +// === /foo/types/index.ts === +// import * as /*RENAME*/[|fooRENAME|] from './types'; +// export { [|fooRENAME|] as foo/*END SUFFIX*/ }; + + + +// === findRenameLocations === +// === /app.ts === +// import { [|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|fooRENAME|].Full; + +// === /foo/types/index.ts === +// import * as foo from './types'; +// export { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] }; + + + +// === findRenameLocations === +// === /app.ts === +// import { [|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; + +// === /foo/types/index.ts === +// import * as foo from './types'; +// export { /*START PREFIX*/foo as [|fooRENAME|] }; + + + +// === findRenameLocations === +// === /app.ts === +// import { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.Full; + + + +// === findRenameLocations === +// === /app.ts === +// import { /*START PREFIX*/foo as [|fooRENAME|] } from './foo/types'; +// export type fullType = /*RENAME*/[|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.Full; + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /app.ts === +// import { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.Full; + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /app.ts === +// import { /*START PREFIX*/foo as [|fooRENAME|] } from './foo/types'; +// export type fullType = /*RENAME*/[|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').foo.Full; + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /app.ts === +// import { [|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; + +// === /foo/types/index.ts === +// import * as foo from './types'; +// export { /*START PREFIX*/foo as [|fooRENAME|] }; + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /foo/types/index.ts === +// import * as /*RENAME*/[|fooRENAME|] from './types'; +// export { [|fooRENAME|] as foo/*END SUFFIX*/ }; + + + +// === findRenameLocations === +// @useAliasesForRename: false + +// === /app.ts === +// import { [|fooRENAME|] } from './foo/types'; +// export type fullType = [|fooRENAME|].Full; +// type namespaceImport = typeof import('./foo/types'); +// type fullType2 = import('./foo/types').[|fooRENAME|].Full; + +// === /foo/types/index.ts === +// import * as foo from './types'; +// export { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc.diff new file mode 100644 index 0000000000..4a58f402ef --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc.diff @@ -0,0 +1,285 @@ +--- old.findAllRefsReExportsUseInImportType.baseline.jsonc ++++ new.findAllRefsReExportsUseInImportType.baseline.jsonc +@@= skipped -0, +0 lines =@@ + // === findRenameLocations === ++// === /app.ts === ++// import { foo } from './foo/types'; ++// export type fullType = foo.[|FullRENAME|]; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').foo.[|FullRENAME|]; ++ + // === /foo/types/types.ts === + // export type /*RENAME*/[|FullRENAME|] = { prop: string; }; + +-// === /app.ts === +-// import { foo } from './foo/types'; +-// export type fullType = foo.[|FullRENAME|]; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').foo.[|FullRENAME|]; +- + + + // === findRenameLocations === +-// === /foo/types/types.ts === +-// export type [|FullRENAME|] = { prop: string; }; +- + // === /app.ts === + // import { foo } from './foo/types'; + // export type fullType = foo./*RENAME*/[|FullRENAME|]; + // type namespaceImport = typeof import('./foo/types'); + // type fullType2 = import('./foo/types').foo.[|FullRENAME|]; + +- +- +-// === findRenameLocations === + // === /foo/types/types.ts === + // export type [|FullRENAME|] = { prop: string; }; + ++ ++ ++// === findRenameLocations === + // === /app.ts === + // import { foo } from './foo/types'; + // export type fullType = foo.[|FullRENAME|]; + // type namespaceImport = typeof import('./foo/types'); + // type fullType2 = import('./foo/types').foo./*RENAME*/[|FullRENAME|]; + +- +- +-// === findRenameLocations === +-// === /foo/types/index.ts === +-// import * as /*RENAME*/[|fooRENAME|] from './types'; +-// export { [|fooRENAME|] as foo/*END SUFFIX*/ }; +- +- +- +-// === findRenameLocations === +-// === /foo/types/index.ts === +-// import * as foo from './types'; +-// export { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] }; +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').[|fooRENAME|].Full; +- +- +- +-// === findRenameLocations === +-// === /foo/types/index.ts === +-// import * as foo from './types'; +-// export { /*START PREFIX*/foo as [|fooRENAME|] }; +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; +- +- +- +-// === findRenameLocations === +-// === /app.ts === +-// import { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').foo.Full; +- +- +- +-// === findRenameLocations === +-// === /app.ts === +-// import { /*START PREFIX*/foo as [|fooRENAME|] } from './foo/types'; +-// export type fullType = /*RENAME*/[|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').foo.Full; +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /app.ts === +-// import { /*RENAME*/[|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').[|fooRENAME|].Full; +- +-// === /foo/types/index.ts === +-// import * as [|fooRENAME|] from './types'; +-// export { [|fooRENAME|] }; +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = /*RENAME*/[|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').[|fooRENAME|].Full; +- +-// === /foo/types/index.ts === +-// import * as [|fooRENAME|] from './types'; +-// export { [|fooRENAME|] }; +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /foo/types/index.ts === +-// import * as [|fooRENAME|] from './types'; +-// export { [|fooRENAME|] }; +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /foo/types/index.ts === +-// import * as /*RENAME*/[|fooRENAME|] from './types'; +-// export { [|fooRENAME|] }; +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').[|fooRENAME|].Full; +- +- +- +-// === findRenameLocations === +-// @useAliasesForRename: false +- +-// === /foo/types/index.ts === +-// import * as [|fooRENAME|] from './types'; +-// export { /*RENAME*/[|fooRENAME|] }; +- +-// === /app.ts === +-// import { [|fooRENAME|] } from './foo/types'; +-// export type fullType = [|fooRENAME|].Full; +-// type namespaceImport = typeof import('./foo/types'); +-// type fullType2 = import('./foo/types').[|fooRENAME|].Full; ++// === /foo/types/types.ts === ++// export type [|FullRENAME|] = { prop: string; }; ++ ++ ++ ++// === findRenameLocations === ++// === /foo/types/index.ts === ++// import * as /*RENAME*/[|fooRENAME|] from './types'; ++// export { [|fooRENAME|] as foo/*END SUFFIX*/ }; ++ ++ ++ ++// === findRenameLocations === ++// === /app.ts === ++// import { [|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').[|fooRENAME|].Full; ++ ++// === /foo/types/index.ts === ++// import * as foo from './types'; ++// export { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] }; ++ ++ ++ ++// === findRenameLocations === ++// === /app.ts === ++// import { [|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; ++ ++// === /foo/types/index.ts === ++// import * as foo from './types'; ++// export { /*START PREFIX*/foo as [|fooRENAME|] }; ++ ++ ++ ++// === findRenameLocations === ++// === /app.ts === ++// import { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').foo.Full; ++ ++ ++ ++// === findRenameLocations === ++// === /app.ts === ++// import { /*START PREFIX*/foo as [|fooRENAME|] } from './foo/types'; ++// export type fullType = /*RENAME*/[|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').foo.Full; ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /app.ts === ++// import { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').foo.Full; ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /app.ts === ++// import { /*START PREFIX*/foo as [|fooRENAME|] } from './foo/types'; ++// export type fullType = /*RENAME*/[|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').foo.Full; ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /app.ts === ++// import { [|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types')./*RENAME*/[|fooRENAME|].Full; ++ ++// === /foo/types/index.ts === ++// import * as foo from './types'; ++// export { /*START PREFIX*/foo as [|fooRENAME|] }; ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /foo/types/index.ts === ++// import * as /*RENAME*/[|fooRENAME|] from './types'; ++// export { [|fooRENAME|] as foo/*END SUFFIX*/ }; ++ ++ ++ ++// === findRenameLocations === ++// @useAliasesForRename: false ++ ++// === /app.ts === ++// import { [|fooRENAME|] } from './foo/types'; ++// export type fullType = [|fooRENAME|].Full; ++// type namespaceImport = typeof import('./foo/types'); ++// type fullType2 = import('./foo/types').[|fooRENAME|].Full; ++ ++// === /foo/types/index.ts === ++// import * as foo from './types'; ++// export { /*START PREFIX*/foo as /*RENAME*/[|fooRENAME|] }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc new file mode 100644 index 0000000000..6f42c66f2a --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc @@ -0,0 +1,31 @@ +// === findRenameLocations === +// === /a.ts === +// export const /*RENAME*/[|xRENAME|] = 0; + +// === /b.ts === +// import { [|xRENAME|] as [|xRENAME|] } from "./a"; +// [|xRENAME|]; + + + +// === findRenameLocations === +// === /a.ts === +// export const [|xRENAME|] = 0; + +// === /b.ts === +// import { /*RENAME*/[|xRENAME|] as [|xRENAME|] } from "./a"; +// [|xRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// import { x as /*RENAME*/[|xRENAME|] } from "./a"; +// [|xRENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// import { x as [|xRENAME|] } from "./a"; +// /*RENAME*/[|xRENAME|]; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc.diff new file mode 100644 index 0000000000..e08c8cb301 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsRenameImportWithSameName.baseline.jsonc.diff @@ -0,0 +1,19 @@ +--- old.findAllRefsRenameImportWithSameName.baseline.jsonc ++++ new.findAllRefsRenameImportWithSameName.baseline.jsonc +@@= skipped -2, +2 lines =@@ + // export const /*RENAME*/[|xRENAME|] = 0; + + // === /b.ts === +-// import { [|{| contextId: 1 |}xRENAME|] as [|{| contextId: 2 |}xRENAME|] } from "./a"; ++// import { [|xRENAME|] as [|xRENAME|] } from "./a"; + // [|xRENAME|]; + + +@@= skipped -10, +10 lines =@@ + // export const [|xRENAME|] = 0; + + // === /b.ts === +-// import { /*RENAME*/[|{| contextId: 1 |}xRENAME|] as [|{| contextId: 2 |}xRENAME|] } from "./a"; ++// import { /*RENAME*/[|xRENAME|] as [|xRENAME|] } from "./a"; + // [|xRENAME|]; + diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInFor.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInFor.baseline.jsonc new file mode 100644 index 0000000000..a81d106f48 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInFor.baseline.jsonc @@ -0,0 +1,76 @@ +// === findRenameLocations === +// === /renameDestructuringAssignmentInFor.ts === +// interface I { +// /*RENAME*/[|property1RENAME|]: number; +// property2: string; +// } +// var elems: I[]; +// +// var p2: number, property1: number; +// for ({ [|property1RENAME|]: property1/*END SUFFIX*/ } = elems[0]; p2 < 100; p2++) { +// p2 = property1++; +// } +// for ({ [|property1RENAME|]: p2 } = elems[0]; p2 < 100; p2++) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInFor.ts === +// interface I { +// [|property1RENAME|]: number; +// property2: string; +// } +// var elems: I[]; +// +// var p2: number, property1: number; +// for ({ [|property1RENAME|]: property1/*END SUFFIX*/ } = elems[0]; p2 < 100; p2++) { +// p2 = property1++; +// } +// for ({ /*RENAME*/[|property1RENAME|]: p2 } = elems[0]; p2 < 100; p2++) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInFor.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var p2: number, /*RENAME*/[|property1RENAME|]: number; +// for ({ /*START PREFIX*/property1: [|property1RENAME|] } = elems[0]; p2 < 100; p2++) { +// p2 = [|property1RENAME|]++; +// } +// for ({ property1: p2 } = elems[0]; p2 < 100; p2++) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInFor.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var p2: number, [|property1RENAME|]: number; +// for ({ /*START PREFIX*/property1: /*RENAME*/[|property1RENAME|] } = elems[0]; p2 < 100; p2++) { +// p2 = [|property1RENAME|]++; +// } +// for ({ property1: p2 } = elems[0]; p2 < 100; p2++) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInFor.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var p2: number, [|property1RENAME|]: number; +// for ({ /*START PREFIX*/property1: [|property1RENAME|] } = elems[0]; p2 < 100; p2++) { +// p2 = /*RENAME*/[|property1RENAME|]++; +// } +// for ({ property1: p2 } = elems[0]; p2 < 100; p2++) { +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInForOf.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInForOf.baseline.jsonc new file mode 100644 index 0000000000..b1ef200017 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentInForOf.baseline.jsonc @@ -0,0 +1,76 @@ +// === findRenameLocations === +// === /renameDestructuringAssignmentInForOf.ts === +// interface I { +// /*RENAME*/[|property1RENAME|]: number; +// property2: string; +// } +// var elems: I[]; +// +// var property1: number, p2: number; +// for ({ [|property1RENAME|]: property1/*END SUFFIX*/ } of elems) { +// property1++; +// } +// for ({ [|property1RENAME|]: p2 } of elems) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInForOf.ts === +// interface I { +// [|property1RENAME|]: number; +// property2: string; +// } +// var elems: I[]; +// +// var property1: number, p2: number; +// for ({ [|property1RENAME|]: property1/*END SUFFIX*/ } of elems) { +// property1++; +// } +// for ({ /*RENAME*/[|property1RENAME|]: p2 } of elems) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInForOf.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var /*RENAME*/[|property1RENAME|]: number, p2: number; +// for ({ /*START PREFIX*/property1: [|property1RENAME|] } of elems) { +// [|property1RENAME|]++; +// } +// for ({ property1: p2 } of elems) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInForOf.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var [|property1RENAME|]: number, p2: number; +// for ({ /*START PREFIX*/property1: /*RENAME*/[|property1RENAME|] } of elems) { +// [|property1RENAME|]++; +// } +// for ({ property1: p2 } of elems) { +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentInForOf.ts === +// --- (line: 3) skipped --- +// } +// var elems: I[]; +// +// var [|property1RENAME|]: number, p2: number; +// for ({ /*START PREFIX*/property1: [|property1RENAME|] } of elems) { +// /*RENAME*/[|property1RENAME|]++; +// } +// for ({ property1: p2 } of elems) { +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor.baseline.jsonc new file mode 100644 index 0000000000..f8c661d802 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor.baseline.jsonc @@ -0,0 +1,83 @@ +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor.ts === +// interface MultiRobot { +// name: string; +// skills: { +// /*RENAME*/[|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, primary: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { [|primaryRENAME|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } = multiRobot, i = 0; i < 1; i++) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor.ts === +// interface MultiRobot { +// name: string; +// skills: { +// [|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, primary: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { /*RENAME*/[|primaryRENAME|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } = multiRobot, i = 0; i < 1; i++) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, /*RENAME*/[|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: /*RENAME*/[|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// /*RENAME*/[|primaryRENAME|]; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor2.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor2.baseline.jsonc new file mode 100644 index 0000000000..4ad314848f --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInFor2.baseline.jsonc @@ -0,0 +1,83 @@ +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor2.ts === +// interface MultiRobot { +// name: string; +// skills: { +// /*RENAME*/[|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, primary: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { [|primaryRENAME|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } = multiRobot, i = 0; i < 1; i++) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor2.ts === +// interface MultiRobot { +// name: string; +// skills: { +// [|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, primary: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { /*RENAME*/[|primaryRENAME|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } = multiRobot, i = 0; i < 1; i++) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor2.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, /*RENAME*/[|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor2.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: /*RENAME*/[|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInFor2.ts === +// --- (line: 4) skipped --- +// secondary: string; +// }; +// } +// let multiRobot: MultiRobot, [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } = multiRobot, i = 0; i < 1; i++) { +// /*RENAME*/[|primaryRENAME|]; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInForOf.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInForOf.baseline.jsonc new file mode 100644 index 0000000000..f0c86c24bc --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameDestructuringAssignmentNestedInForOf.baseline.jsonc @@ -0,0 +1,85 @@ +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInForOf.ts === +// interface MultiRobot { +// name: string; +// skills: { +// /*RENAME*/[|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobots: MultiRobot[]; +// let primary: string, secondary: string, primaryA: string, secondaryA: string; +// for ({ skills: { [|primaryRENAME|]: primaryA, secondary: secondaryA } } of multiRobots) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } of multiRobots) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInForOf.ts === +// interface MultiRobot { +// name: string; +// skills: { +// [|primaryRENAME|]: string; +// secondary: string; +// }; +// } +// let multiRobots: MultiRobot[]; +// let primary: string, secondary: string, primaryA: string, secondaryA: string; +// for ({ skills: { /*RENAME*/[|primaryRENAME|]: primaryA, secondary: secondaryA } } of multiRobots) { +// primaryA; +// } +// for ({ skills: { [|primaryRENAME|]: primary/*END SUFFIX*/, secondary } } of multiRobots) { +// primary; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInForOf.ts === +// --- (line: 5) skipped --- +// }; +// } +// let multiRobots: MultiRobot[]; +// let /*RENAME*/[|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } of multiRobots) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } of multiRobots) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInForOf.ts === +// --- (line: 5) skipped --- +// }; +// } +// let multiRobots: MultiRobot[]; +// let [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } of multiRobots) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: /*RENAME*/[|primaryRENAME|], secondary } } of multiRobots) { +// [|primaryRENAME|]; +// } + + + +// === findRenameLocations === +// === /renameDestructuringAssignmentNestedInForOf.ts === +// --- (line: 5) skipped --- +// }; +// } +// let multiRobots: MultiRobot[]; +// let [|primaryRENAME|]: string, secondary: string, primaryA: string, secondaryA: string; +// for ({ skills: { primary: primaryA, secondary: secondaryA } } of multiRobots) { +// primaryA; +// } +// for ({ skills: { /*START PREFIX*/primary: [|primaryRENAME|], secondary } } of multiRobots) { +// /*RENAME*/[|primaryRENAME|]; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfExportEquals2.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfExportEquals2.baseline.jsonc new file mode 100644 index 0000000000..ffc974befa --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfExportEquals2.baseline.jsonc @@ -0,0 +1,111 @@ +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// declare namespace /*RENAME*/[|NRENAME|] { +// export var x: number; +// } +// declare module "mod" { +// export = [|NRENAME|]; +// } +// declare module "a" { +// import * as O from "mod"; +// --- (line: 9) skipped --- + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// declare namespace [|NRENAME|] { +// export var x: number; +// } +// declare module "mod" { +// export = /*RENAME*/[|NRENAME|]; +// } +// declare module "a" { +// import * as O from "mod"; +// --- (line: 9) skipped --- + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 4) skipped --- +// export = N; +// } +// declare module "a" { +// import * as /*RENAME*/[|ORENAME|] from "mod"; +// export { [|ORENAME|] as P }; // Renaming N here would rename +// } +// declare module "b" { +// import { P as Q } from "a"; +// export const y: typeof Q.x; +// } + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 4) skipped --- +// export = N; +// } +// declare module "a" { +// import * as [|ORENAME|] from "mod"; +// export { /*RENAME*/[|ORENAME|] as P }; // Renaming N here would rename +// } +// declare module "b" { +// import { P as Q } from "a"; +// export const y: typeof Q.x; +// } + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 5) skipped --- +// } +// declare module "a" { +// import * as O from "mod"; +// export { O as /*RENAME*/[|PRENAME|] }; // Renaming N here would rename +// } +// declare module "b" { +// import { [|PRENAME|] as Q } from "a"; +// export const y: typeof Q.x; +// } + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 5) skipped --- +// } +// declare module "a" { +// import * as O from "mod"; +// export { O as [|PRENAME|] }; // Renaming N here would rename +// } +// declare module "b" { +// import { /*RENAME*/[|PRENAME|] as Q } from "a"; +// export const y: typeof Q.x; +// } + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 8) skipped --- +// export { O as P }; // Renaming N here would rename +// } +// declare module "b" { +// import { P as /*RENAME*/[|QRENAME|] } from "a"; +// export const y: typeof [|QRENAME|].x; +// } + + + +// === findRenameLocations === +// === /renameImportOfExportEquals2.ts === +// --- (line: 8) skipped --- +// export { O as P }; // Renaming N here would rename +// } +// declare module "b" { +// import { P as [|QRENAME|] } from "a"; +// export const y: typeof /*RENAME*/[|QRENAME|].x; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfReExport.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfReExport.baseline.jsonc new file mode 100644 index 0000000000..a4b5519d9e --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameImportOfReExport.baseline.jsonc @@ -0,0 +1,51 @@ +// === findRenameLocations === +// === /renameImportOfReExport.ts === +// declare module "a" { +// export class /*RENAME*/[|CRENAME|] {} +// } +// declare module "b" { +// export { [|CRENAME|] as C/*END SUFFIX*/ } from "a"; +// } +// declare module "c" { +// import { C } from "b"; +// export function f(c: C): void; +// } + + + +// === findRenameLocations === +// === /renameImportOfReExport.ts === +// declare module "a" { +// export class C {} +// } +// declare module "b" { +// export { /*START PREFIX*/C as /*RENAME*/[|CRENAME|] } from "a"; +// } +// declare module "c" { +// import { [|CRENAME|] } from "b"; +// export function f(c: [|CRENAME|]): void; +// } + + + +// === findRenameLocations === +// === /renameImportOfReExport.ts === +// --- (line: 4) skipped --- +// export { C } from "a"; +// } +// declare module "c" { +// import { /*START PREFIX*/C as /*RENAME*/[|CRENAME|] } from "b"; +// export function f(c: [|CRENAME|]): void; +// } + + + +// === findRenameLocations === +// === /renameImportOfReExport.ts === +// --- (line: 4) skipped --- +// export { C } from "a"; +// } +// declare module "c" { +// import { /*START PREFIX*/C as [|CRENAME|] } from "b"; +// export function f(c: /*RENAME*/[|CRENAME|]): void; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports.baseline.jsonc new file mode 100644 index 0000000000..ce046c8fc2 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports.baseline.jsonc @@ -0,0 +1,47 @@ +// === findRenameLocations === +// === /a.ts === +// class /*RENAME*/[|ARENAME|] { +// } +// export = [|ARENAME|]; + + + +// === findRenameLocations === +// === /a.ts === +// class [|ARENAME|] { +// } +// export = /*RENAME*/[|ARENAME|]; + + + +// === findRenameLocations === +// === /b.ts === +// export import /*RENAME*/[|bRENAME|] = require('./a'); + +// === /c.ts === +// import b = require('./b'); +// var a = new b.[|bRENAME|](); + + + +// === findRenameLocations === +// === /b.ts === +// export import [|bRENAME|] = require('./a'); + +// === /c.ts === +// import b = require('./b'); +// var a = new b./*RENAME*/[|bRENAME|](); + + + +// === findRenameLocations === +// === /c.ts === +// import /*RENAME*/[|bRENAME|] = require('./b'); +// var a = new [|bRENAME|].b(); + + + +// === findRenameLocations === +// === /c.ts === +// import [|bRENAME|] = require('./b'); +// var a = new /*RENAME*/[|bRENAME|].b(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports2.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports2.baseline.jsonc new file mode 100644 index 0000000000..6a07d4c58e --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports2.baseline.jsonc @@ -0,0 +1,47 @@ +// === findRenameLocations === +// === /a.ts === +// namespace /*RENAME*/[|ARENAME|] { +// export const x = 0; +// } + +// === /b.ts === +// export import B = [|ARENAME|]; +// B.x; + + + +// === findRenameLocations === +// === /a.ts === +// namespace [|ARENAME|] { +// export const x = 0; +// } + +// === /b.ts === +// export import B = /*RENAME*/[|ARENAME|]; +// B.x; + + + +// === findRenameLocations === +// === /b.ts === +// export import /*RENAME*/[|BRENAME|] = A; +// [|BRENAME|].x; + +// === /c.ts === +// import { [|BRENAME|] } from "./b"; + + + +// === findRenameLocations === +// === /b.ts === +// export import [|BRENAME|] = A; +// /*RENAME*/[|BRENAME|].x; + +// === /c.ts === +// import { [|BRENAME|] } from "./b"; + + + +// === findRenameLocations === +// === /c.ts === +// import { /*START PREFIX*/B as /*RENAME*/[|BRENAME|] } from "./b"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports3.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports3.baseline.jsonc new file mode 100644 index 0000000000..b323a04abb --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/transitiveExportImports3.baseline.jsonc @@ -0,0 +1,43 @@ +// === findRenameLocations === +// === /a.ts === +// export function /*RENAME*/[|fRENAME|]() {} + +// === /b.ts === +// export { [|fRENAME|] as g } from "./a"; +// import { [|fRENAME|] } from "./a"; +// import { g } from "./b"; + + + +// === findRenameLocations === +// === /a.ts === +// export function [|fRENAME|]() {} + +// === /b.ts === +// export { /*RENAME*/[|fRENAME|] as g } from "./a"; +// import { [|fRENAME|] } from "./a"; +// import { g } from "./b"; + + + +// === findRenameLocations === +// === /b.ts === +// export { f as g } from "./a"; +// import { /*START PREFIX*/f as /*RENAME*/[|fRENAME|] } from "./a"; +// import { g } from "./b"; + + + +// === findRenameLocations === +// === /b.ts === +// export { f as /*RENAME*/[|gRENAME|] } from "./a"; +// import { f } from "./a"; +// import { [|gRENAME|] } from "./b"; + + + +// === findRenameLocations === +// === /b.ts === +// export { f as g } from "./a"; +// import { f } from "./a"; +// import { /*START PREFIX*/g as /*RENAME*/[|gRENAME|] } from "./b"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc new file mode 100644 index 0000000000..d8cd4e6251 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc @@ -0,0 +1,91 @@ +// === findRenameLocations === +// === /file.tsx === +// --- (line: 3) skipped --- +// div: {}; +// } +// } +// class /*RENAME*/[|MyClassRENAME|] {} +// +// <[|MyClassRENAME|]>; +// <[|MyClassRENAME|]/>; +// +//

+ + + +// === findRenameLocations === +// === /file.tsx === +// --- (line: 3) skipped --- +// div: {}; +// } +// } +// class [|MyClassRENAME|] {} +// +// ; +// <[|MyClassRENAME|]/>; +// +//
+ + + +// === findRenameLocations === +// === /file.tsx === +// --- (line: 3) skipped --- +// div: {}; +// } +// } +// class [|MyClassRENAME|] {} +// +// <[|MyClassRENAME|]>; +// <[|MyClassRENAME|]/>; +// +//
+ + + +// === findRenameLocations === +// === /file.tsx === +// --- (line: 3) skipped --- +// div: {}; +// } +// } +// class [|MyClassRENAME|] {} +// +// <[|MyClassRENAME|]>; +// ; +// +//
+ + + +// === findRenameLocations === +// === /file.tsx === +// declare module JSX { +// interface Element {} +// interface IntrinsicElements { +// [|divRENAME|]: {}; +// } +// } +// class MyClass {} +// +// ; +// ; +// +// + + + +// === findRenameLocations === +// === /file.tsx === +// declare module JSX { +// interface Element {} +// interface IntrinsicElements { +// [|divRENAME|]: {}; +// } +// } +// class MyClass {} +// +// ; +// ; +// +// <[|divRENAME|]> \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc.diff new file mode 100644 index 0000000000..8c997b897f --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename4.baseline.jsonc.diff @@ -0,0 +1,135 @@ +--- old.tsxRename4.baseline.jsonc ++++ new.tsxRename4.baseline.jsonc +@@= skipped -5, +5 lines =@@ + // } + // class /*RENAME*/[|MyClassRENAME|] {} + // +-// <[|{| contextId: 1 |}MyClassRENAME|]>; +-// <[|MyClassRENAME|]/>; +-// +-//
+- +- +- +-// === findRenameLocations === +-// === /file.tsx === +-// --- (line: 3) skipped --- +-// div: {}; +-// } +-// } +-// class [|MyClassRENAME|] {} +-// +-// ; +-// <[|MyClassRENAME|]/>; +-// +-//
+- +- +- +-// === findRenameLocations === +-// === /file.tsx === +-// --- (line: 3) skipped --- +-// div: {}; +-// } +-// } +-// class [|MyClassRENAME|] {} +-// +-// <[|{| contextId: 1 |}MyClassRENAME|]>; +-// <[|MyClassRENAME|]/>; +-// +-//
+- +- +- +-// === findRenameLocations === +-// === /file.tsx === +-// --- (line: 3) skipped --- +-// div: {}; +-// } +-// } +-// class [|MyClassRENAME|] {} +-// +-// <[|{| contextId: 1 |}MyClassRENAME|]>; ++// <[|MyClassRENAME|]>; ++// <[|MyClassRENAME|]/>; ++// ++//
++ ++ ++ ++// === findRenameLocations === ++// === /file.tsx === ++// --- (line: 3) skipped --- ++// div: {}; ++// } ++// } ++// class [|MyClassRENAME|] {} ++// ++// ; ++// <[|MyClassRENAME|]/>; ++// ++//
++ ++ ++ ++// === findRenameLocations === ++// === /file.tsx === ++// --- (line: 3) skipped --- ++// div: {}; ++// } ++// } ++// class [|MyClassRENAME|] {} ++// ++// <[|MyClassRENAME|]>; ++// <[|MyClassRENAME|]/>; ++// ++//
++ ++ ++ ++// === findRenameLocations === ++// === /file.tsx === ++// --- (line: 3) skipped --- ++// div: {}; ++// } ++// } ++// class [|MyClassRENAME|] {} ++// ++// <[|MyClassRENAME|]>; + // ; + // + //
++ ++ ++ ++// === findRenameLocations === ++// === /file.tsx === ++// declare module JSX { ++// interface Element {} ++// interface IntrinsicElements { ++// [|divRENAME|]: {}; ++// } ++// } ++// class MyClass {} ++// ++// ; ++// ; ++// ++// ++ ++ ++ ++// === findRenameLocations === ++// === /file.tsx === ++// declare module JSX { ++// interface Element {} ++// interface IntrinsicElements { ++// [|divRENAME|]: {}; ++// } ++// } ++// class MyClass {} ++// ++// ; ++// ; ++// ++// <[|divRENAME|]> \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors1.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors1.baseline.jsonc new file mode 100644 index 0000000000..f245e8a34c --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors1.baseline.jsonc @@ -0,0 +1,5 @@ +// === goToDefinition === +// === /asConstRefsNoErrors1.ts === +// class Tex { +// type = 'Text' as /*GOTO DEF*/const; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors2.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors2.baseline.jsonc new file mode 100644 index 0000000000..cdb223047f --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors2.baseline.jsonc @@ -0,0 +1,5 @@ +// === goToDefinition === +// === /asConstRefsNoErrors2.ts === +// class Tex { +// type = 'Text'; +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors3.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors3.baseline.jsonc new file mode 100644 index 0000000000..82b8b53420 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/asConstRefsNoErrors3.baseline.jsonc @@ -0,0 +1,5 @@ +// === goToDefinition === +// === /file.js === +// class Tex { +// type = (/** @type {/*GOTO DEF*/const} */'Text'); +// } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionImportMeta.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionImportMeta.baseline.jsonc new file mode 100644 index 0000000000..d2d4f0e098 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionImportMeta.baseline.jsonc @@ -0,0 +1,5 @@ +// === goToDefinition === +// === /foo.ts === +// /// +// /// +// import.me/*GOTO DEF*/ta; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc new file mode 100644 index 0000000000..e0e7437d4b --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc @@ -0,0 +1,251 @@ +// === goToDefinition === +// === /a.tsx === +// <|function [|f|]() {}|> +// const g = f; +// const h = g; +// /*GOTO DEF*/f(); +// g(); +// h(); +// const i = () => 0; +// --- (line: 8) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// <|function [|f|]() {}|> +// <|const [|g|] = f;|> +// const h = g; +// f(); +// /*GOTO DEF*/g(); +// h(); +// const i = () => 0; +// const iFn = function () { return 0; }; +// --- (line: 9) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// <|function [|f|]() {}|> +// const g = f; +// <|const [|h|] = g;|> +// f(); +// g(); +// /*GOTO DEF*/h(); +// const i = () => 0; +// const iFn = function () { return 0; }; +// const j = i; +// --- (line: 10) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 3) skipped --- +// f(); +// g(); +// h(); +// <|const [|i|] = () => 0;|> +// const iFn = function () { return 0; }; +// const j = i; +// /*GOTO DEF*/i(); +// iFn(); +// j(); +// const o = { m: () => 0 }; +// --- (line: 14) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 4) skipped --- +// g(); +// h(); +// const i = () => 0; +// <|const [|iFn|] = function () { return 0; };|> +// const j = i; +// i(); +// /*GOTO DEF*/iFn(); +// j(); +// const o = { m: () => 0 }; +// o.m(); +// --- (line: 15) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 3) skipped --- +// f(); +// g(); +// h(); +// const [|i|] = <|() => 0|>; +// const iFn = function () { return 0; }; +// <|const [|j|] = i;|> +// i(); +// iFn(); +// /*GOTO DEF*/j(); +// const o = { m: () => 0 }; +// o.m(); +// const oFn = { mFn: function () { return 0; } }; +// --- (line: 16) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 9) skipped --- +// i(); +// iFn(); +// j(); +// const o = { <|[|m|]: () => 0|> }; +// o./*GOTO DEF*/m(); +// const oFn = { mFn: function () { return 0; } }; +// oFn.mFn(); +// class Component { constructor(props: {}) {} } +// --- (line: 18) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 11) skipped --- +// j(); +// const o = { m: () => 0 }; +// o.m(); +// const oFn = { <|[|mFn|]: function () { return 0; }|> }; +// oFn./*GOTO DEF*/mFn(); +// class Component { constructor(props: {}) {} } +// type ComponentClass = new () => Component; +// interface ComponentClass2 { new(): Component; } +// --- (line: 20) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 13) skipped --- +// o.m(); +// const oFn = { mFn: function () { return 0; } }; +// oFn.mFn(); +// class Component { [|constructor(props: {}) {}|] } +// type ComponentClass = new () => Component; +// interface ComponentClass2 { new(): Component; } +// +// <|class [|MyComponent|] extends Component {}|> +// ; +// new MyComponent({}); +// +// declare const MyComponent2: ComponentClass; +// --- (line: 26) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 13) skipped --- +// o.m(); +// const oFn = { mFn: function () { return 0; } }; +// oFn.mFn(); +// class Component { [|constructor(props: {}) {}|] } +// type ComponentClass = new () => Component; +// interface ComponentClass2 { new(): Component; } +// +// <|class [|MyComponent|] extends Component {}|> +// ; +// new /*GOTO DEF*/MyComponent({}); +// +// declare const MyComponent2: ComponentClass; +// ; +// --- (line: 27) skipped --- + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 14) skipped --- +// const oFn = { mFn: function () { return 0; } }; +// oFn.mFn(); +// class Component { constructor(props: {}) {} } +// type ComponentClass = [|new () => Component|]; +// interface ComponentClass2 { new(): Component; } +// +// class MyComponent extends Component {} +// ; +// new MyComponent({}); +// +// <|declare const [|MyComponent2|]: ComponentClass;|> +// ; +// new MyComponent2(); +// +// declare const MyComponent3: ComponentClass2; +// ; +// new MyComponent3(); + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 14) skipped --- +// const oFn = { mFn: function () { return 0; } }; +// oFn.mFn(); +// class Component { constructor(props: {}) {} } +// type ComponentClass = [|new () => Component|]; +// interface ComponentClass2 { new(): Component; } +// +// class MyComponent extends Component {} +// ; +// new MyComponent({}); +// +// <|declare const [|MyComponent2|]: ComponentClass;|> +// ; +// new /*GOTO DEF*/MyComponent2(); +// +// declare const MyComponent3: ComponentClass2; +// ; +// new MyComponent3(); + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 15) skipped --- +// oFn.mFn(); +// class Component { constructor(props: {}) {} } +// type ComponentClass = new () => Component; +// interface ComponentClass2 { [|new(): Component;|] } +// +// class MyComponent extends Component {} +// ; +// new MyComponent({}); +// +// declare const MyComponent2: ComponentClass; +// ; +// new MyComponent2(); +// +// <|declare const [|MyComponent3|]: ComponentClass2;|> +// ; +// new MyComponent3(); + + + +// === goToDefinition === +// === /a.tsx === +// --- (line: 15) skipped --- +// oFn.mFn(); +// class Component { constructor(props: {}) {} } +// type ComponentClass = new () => Component; +// interface ComponentClass2 { [|new(): Component;|] } +// +// class MyComponent extends Component {} +// ; +// new MyComponent({}); +// +// declare const MyComponent2: ComponentClass; +// ; +// new MyComponent2(); +// +// <|declare const [|MyComponent3|]: ComponentClass2;|> +// ; +// new /*GOTO DEF*/MyComponent3(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc.diff b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc.diff new file mode 100644 index 0000000000..5da7cc7d0c --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/goToDefinitionSignatureAlias.baseline.jsonc.diff @@ -0,0 +1,86 @@ +--- old.goToDefinitionSignatureAlias.baseline.jsonc ++++ new.goToDefinitionSignatureAlias.baseline.jsonc +@@= skipped -45, +45 lines =@@ + // f(); + // g(); + // h(); +-// const [|i|] = <|() => 0|>; ++// <|const [|i|] = () => 0;|> + // const iFn = function () { return 0; }; + // const j = i; + // /*GOTO DEF*/i(); +@@= skipped -17, +17 lines =@@ + // g(); + // h(); + // const i = () => 0; +-// const [|iFn|] = <|function () { return 0; }|>; ++// <|const [|iFn|] = function () { return 0; };|> + // const j = i; + // i(); + // /*GOTO DEF*/iFn(); +@@= skipped -36, +36 lines =@@ + // i(); + // iFn(); + // j(); +-// const o = { [|m|]: <|() => 0|> }; ++// const o = { <|[|m|]: () => 0|> }; + // o./*GOTO DEF*/m(); + // const oFn = { mFn: function () { return 0; } }; + // oFn.mFn(); +@@= skipped -15, +15 lines =@@ + // j(); + // const o = { m: () => 0 }; + // o.m(); +-// const oFn = { [|mFn|]: <|function () { return 0; }|> }; ++// const oFn = { <|[|mFn|]: function () { return 0; }|> }; + // oFn./*GOTO DEF*/mFn(); + // class Component { constructor(props: {}) {} } + // type ComponentClass = new () => Component; +@@= skipped -11, +11 lines =@@ + + // === goToDefinition === + // === /a.tsx === +-// --- (line: 17) skipped --- ++// --- (line: 13) skipped --- ++// o.m(); ++// const oFn = { mFn: function () { return 0; } }; ++// oFn.mFn(); ++// class Component { [|constructor(props: {}) {}|] } + // type ComponentClass = new () => Component; + // interface ComponentClass2 { new(): Component; } + // +@@= skipped -35, +39 lines =@@ + + // === goToDefinition === + // === /a.tsx === +-// --- (line: 21) skipped --- ++// --- (line: 14) skipped --- ++// const oFn = { mFn: function () { return 0; } }; ++// oFn.mFn(); ++// class Component { constructor(props: {}) {} } ++// type ComponentClass = [|new () => Component|]; ++// interface ComponentClass2 { new(): Component; } ++// ++// class MyComponent extends Component {} + // ; + // new MyComponent({}); + // +@@= skipped -39, +46 lines =@@ + + // === goToDefinition === + // === /a.tsx === +-// --- (line: 25) skipped --- ++// --- (line: 15) skipped --- ++// oFn.mFn(); ++// class Component { constructor(props: {}) {} } ++// type ComponentClass = new () => Component; ++// interface ComponentClass2 { [|new(): Component;|] } ++// ++// class MyComponent extends Component {} ++// ; ++// new MyComponent({}); ++// ++// declare const MyComponent2: ComponentClass; + // ; + // new MyComponent2(); + // \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/fourslash/goToDefinition/tsxGoToDefinitionClassInDifferentFile.baseline.jsonc b/testdata/baselines/reference/submodule/fourslash/goToDefinition/tsxGoToDefinitionClassInDifferentFile.baseline.jsonc new file mode 100644 index 0000000000..4851414df1 --- /dev/null +++ b/testdata/baselines/reference/submodule/fourslash/goToDefinition/tsxGoToDefinitionClassInDifferentFile.baseline.jsonc @@ -0,0 +1,7 @@ +// === goToDefinition === +// === /C.tsx === +// <|export default class [|C|] {}|> + +// === /a.tsx === +// import C from "./C"; +// const foo = ; \ No newline at end of file