diff --git a/internal/collections/multimap.go b/internal/collections/multimap.go index 6da7638181..51029e8c0a 100644 --- a/internal/collections/multimap.go +++ b/internal/collections/multimap.go @@ -10,6 +10,14 @@ type MultiMap[K comparable, V comparable] struct { M map[K][]V } +func GroupBy[K comparable, V comparable](items []V, groupId func(V) K) *MultiMap[K, V] { + m := &MultiMap[K, V]{} + for _, item := range items { + m.Add(groupId(item), item) + } + return m +} + func (s *MultiMap[K, V]) Has(key K) bool { _, ok := s.M[key] return ok diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index 02051e5bd7..bdfcf4c50b 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -137,9 +137,16 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { console.error(`Expected identifiers for namespace and function, got ${namespace.getText()} and ${func.getText()}`); return undefined; } - // `verify.completions(...)` - if (namespace.text === "verify" && func.text === "completions") { - return parseVerifyCompletionsArgs(callExpression.arguments); + // `verify.(...)` + if (namespace.text === "verify") { + switch (func.text) { + case "completions": + // `verify.completions(...)` + return parseVerifyCompletionsArgs(callExpression.arguments); + case "baselineFindAllReferences": + // `verify.baselineFindAllReferences(...)` + return [parseBaselineFindAllReferencesArgs(callExpression.arguments)]; + } } // `goTo.marker(...)` if (namespace.text === "goTo" && func.text === "marker") { @@ -405,6 +412,27 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined { return undefined; // Unsupported expression type } +function parseBaselineFindAllReferencesArgs(args: readonly ts.Expression[]): VerifyBaselineFindAllReferencesCmd { + const newArgs = []; + for (const arg of args) { + if (ts.isStringLiteral(arg)) { + newArgs.push(getGoStringLiteral(arg.text)); + } + else if (arg.getText() === "...test.ranges()") { + return { + kind: "verifyBaselineFindAllReferences", + markers: [], + ranges: true, + }; + } + } + + return { + kind: "verifyBaselineFindAllReferences", + markers: newArgs, + }; +} + function parseKind(expr: ts.Expression): string | undefined { if (!ts.isStringLiteral(expr)) { console.error(`Expected string literal for kind, got ${expr.getText()}`); @@ -530,12 +558,18 @@ interface VerifyCompletionsArgs { exact?: string; } +interface VerifyBaselineFindAllReferencesCmd { + kind: "verifyBaselineFindAllReferences"; + markers: string[]; + ranges?: boolean; +} + interface GoToMarkerCmd { kind: "goToMarker"; marker: string; } -type Cmd = VerifyCompletionsCmd | GoToMarkerCmd; +type Cmd = VerifyCompletionsCmd | GoToMarkerCmd | VerifyBaselineFindAllReferencesCmd; function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: VerifyCompletionsCmd): string { let expectedList = "nil"; @@ -560,6 +594,13 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve return `f.VerifyCompletions(t, ${marker}, ${expectedList})`; } +function generateBaselineFindAllReferences({ markers, ranges }: VerifyBaselineFindAllReferencesCmd): string { + if (ranges || markers.length === 0) { + return `f.VerifyBaselineFindAllReferences(t)`; + } + return `f.VerifyBaselineFindAllReferences(t, ${markers.join(", ")})`; +} + function generateGoToMarker({ marker }: GoToMarkerCmd): string { return `f.GoToMarker(t, ${marker})`; } @@ -568,6 +609,8 @@ function generateCmd(cmd: Cmd): string { switch (cmd.kind) { case "verifyCompletions": return generateVerifyCompletions(cmd as VerifyCompletionsCmd); + case "verifyBaselineFindAllReferences": + return generateBaselineFindAllReferences(cmd as VerifyBaselineFindAllReferencesCmd); case "goToMarker": return generateGoToMarker(cmd as GoToMarkerCmd); default: diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index c2a5739e47..13dd640a11 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -30,6 +30,7 @@ type FourslashTest struct { id int32 testData *TestData + baseline *baselineFromTest currentCaretPosition lsproto.Position currentFilename string @@ -250,16 +251,28 @@ func (f *FourslashTest) GoToMarker(t *testing.T, markerName string) { if !ok { t.Fatalf("Marker %s not found", markerName) } - f.ensureActiveFile(t, marker.FileName) + f.ensureActiveFile(t, marker.fileName) f.currentCaretPosition = marker.LSPosition - f.currentFilename = marker.FileName + f.currentFilename = marker.fileName f.lastKnownMarkerName = marker.Name } +func (f *FourslashTest) GoToPosAndFile(t *testing.T, pos lsproto.Position, fileName string) { + // GoToRangeStart + f.ensureActiveFile(t, fileName) + f.currentCaretPosition = pos + f.currentFilename = fileName + // !!! this.selectionEnd = -1 +} + func (f *FourslashTest) Markers() []*Marker { return f.testData.Markers } +func (f *FourslashTest) Ranges() []*RangeMarker { + return f.testData.Ranges +} + func (f *FourslashTest) ensureActiveFile(t *testing.T, filename string) { if f.activeFilename != filename { file := core.Find(f.testData.Files, func(f *TestFileInfo) bool { @@ -283,6 +296,15 @@ func (f *FourslashTest) openFile(t *testing.T, file *TestFileInfo) { }) } +func (f *FourslashTest) currentTextDocumentPositionParams() lsproto.TextDocumentPositionParams { + return lsproto.TextDocumentPositionParams{ + TextDocument: lsproto.TextDocumentIdentifier{ + Uri: ls.FileNameToDocumentURI(f.currentFilename), + }, + Position: f.currentCaretPosition, + } +} + func getLanguageKind(filename string) lsproto.LanguageKind { if tspath.FileExtensionIsOneOf( filename, @@ -357,13 +379,8 @@ func (f *FourslashTest) verifyCompletionsAtMarker(t *testing.T, markerName strin func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *VerifyCompletionsExpectedList) { params := &lsproto.CompletionParams{ - TextDocumentPositionParams: lsproto.TextDocumentPositionParams{ - TextDocument: lsproto.TextDocumentIdentifier{ - Uri: ls.FileNameToDocumentURI(f.currentFilename), - }, - Position: f.currentCaretPosition, - }, - Context: &lsproto.CompletionContext{}, + TextDocumentPositionParams: f.currentTextDocumentPositionParams(), + Context: &lsproto.CompletionContext{}, } resMsg := f.sendRequest(t, lsproto.MethodTextDocumentCompletion, params) if resMsg == nil { @@ -503,6 +520,54 @@ func assertDeepEqual(t *testing.T, actual any, expected any, prefix string, opts } } +func (f *FourslashTest) VerifyBaselineFindAllReferences( + t *testing.T, + markers ...string, +) { + // if there are no markers specified, use all ranges + var referenceLocations []MarkerOrRange + if len(markers) == 0 { + referenceLocations = core.Map(f.testData.Ranges, func(r *RangeMarker) MarkerOrRange { return r }) + } else { + referenceLocations = core.Map(markers, func(markerName string) MarkerOrRange { + marker, ok := f.testData.MarkerPositions[markerName] + if !ok { + t.Fatalf("Marker %s not found", markerName) + } + return marker + }) + } + + if f.baseline != nil { + t.Fatalf("Another baseline is already in progress") + } else { + f.baseline = &baselineFromTest{ + baseline: &strings.Builder{}, + testName: t.Name(), + ext: ".baseline.jsonc", + } + } + + for _, markerOrRange := range referenceLocations { + // worker in `baselineEachMarkerOrRange` + f.GoToPosAndFile(t, markerOrRange.LSPos(), markerOrRange.FileName()) + params := &lsproto.ReferenceParams{ + TextDocumentPositionParams: f.currentTextDocumentPositionParams(), + Context: &lsproto.ReferenceContext{}, + } + resMsg := f.sendRequest(t, lsproto.MethodTextDocumentReferences, params) + if resMsg == nil { + t.Fatalf("Nil response received for completion request at marker %s", f.lastKnownMarkerName) + } + result := resMsg.AsResponse().Result + if result, ok := result.([]*lsproto.Location); ok { + // !!! TODO verifyFindAllReferences(t, markerOrRange) + } else { + t.Fatalf("Unexpected response type at marker %s: %v", f.lastKnownMarkerName, result) + } + } +} + func ptrTo[T any](v T) *T { return &v } diff --git a/internal/fourslash/test_parser.go b/internal/fourslash/test_parser.go index 1b84be0181..d23e8dbad9 100644 --- a/internal/fourslash/test_parser.go +++ b/internal/fourslash/test_parser.go @@ -27,14 +27,35 @@ type RangeMarker struct { LSRange lsproto.Range } +func (r *RangeMarker) LSPos() lsproto.Position { + return r.LSRange.Start +} + +func (r *RangeMarker) FileName() string { + return r.fileName +} + type Marker struct { - FileName string + fileName string Position int LSPosition lsproto.Position Name string Data map[string]interface{} } +func (m *Marker) LSPos() lsproto.Position { + return m.LSPosition +} + +func (m *Marker) FileName() string { + return m.fileName +} + +type MarkerOrRange interface { + FileName() string + LSPos() lsproto.Position +} + type TestData struct { Files []*TestFileInfo MarkerPositions map[string]*Marker @@ -211,8 +232,10 @@ func parseFileContent(fileName string, content string, fileOptions map[string]st if rangeStart.marker != nil { closedRange.Marker = rangeStart.marker } else { - // RangeMarker is not added to list of markers - closedRange.Marker = &Marker{FileName: fileName} + // A default RangeMarker is not added to list of markers. If the RangeMarker was created by parsing an actual marker within the range + // in the test file, then the marker should have been added to the marker list when the marker was parsed. + // Similarly, if the RangeMarker has a name, this means that there was a named marker parsed within the range (and has been already included in the marker list) + closedRange.Marker = &Marker{fileName: fileName} } rangeMarkers = append(rangeMarkers, closedRange) @@ -269,7 +292,7 @@ func parseFileContent(fileName string, content string, fileOptions map[string]st // start + 2 to ignore the */, -1 on the end to ignore the * (/ is next) markerNameText := strings.TrimSpace(content[openMarker.sourcePosition+2 : i-1]) marker := &Marker{ - FileName: fileName, + fileName: fileName, Position: openMarker.position, Name: markerNameText, } @@ -372,7 +395,7 @@ func getObjectMarker(fileName string, location *locationInformation, text string } marker := &Marker{ - FileName: fileName, + fileName: fileName, Position: location.position, Data: markerValue, } diff --git a/internal/fourslash/tests/gen/ambientShorthandFindAllRefs_test.go b/internal/fourslash/tests/gen/ambientShorthandFindAllRefs_test.go new file mode 100644 index 0000000000..80de763eed --- /dev/null +++ b/internal/fourslash/tests/gen/ambientShorthandFindAllRefs_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 TestAmbientShorthandFindAllRefs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: declarations.d.ts +declare module "jquery"; +// @Filename: user.ts +import {/*1*/x} from "jquery"; +// @Filename: user2.ts +import {/*2*/x} from "jquery";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/constructorFindAllReferences1_test.go b/internal/fourslash/tests/gen/constructorFindAllReferences1_test.go new file mode 100644 index 0000000000..79bf77e4da --- /dev/null +++ b/internal/fourslash/tests/gen/constructorFindAllReferences1_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 TestConstructorFindAllReferences1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /**/public constructor() { } + public foo() { } +} + +new C().foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/constructorFindAllReferences2_test.go b/internal/fourslash/tests/gen/constructorFindAllReferences2_test.go new file mode 100644 index 0000000000..9c98352fd9 --- /dev/null +++ b/internal/fourslash/tests/gen/constructorFindAllReferences2_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 TestConstructorFindAllReferences2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /**/private constructor() { } + public foo() { } +} + +new C().foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/constructorFindAllReferences3_test.go b/internal/fourslash/tests/gen/constructorFindAllReferences3_test.go new file mode 100644 index 0000000000..82d393dde4 --- /dev/null +++ b/internal/fourslash/tests/gen/constructorFindAllReferences3_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 TestConstructorFindAllReferences3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /**/constructor() { } + public foo() { } +} + +new C().foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/constructorFindAllReferences4_test.go b/internal/fourslash/tests/gen/constructorFindAllReferences4_test.go new file mode 100644 index 0000000000..35fecd29e4 --- /dev/null +++ b/internal/fourslash/tests/gen/constructorFindAllReferences4_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 TestConstructorFindAllReferences4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export class C { + /**/protected constructor() { } + public foo() { } +} + +new C().foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/esModuleInteropFindAllReferences2_test.go b/internal/fourslash/tests/gen/esModuleInteropFindAllReferences2_test.go new file mode 100644 index 0000000000..e46c646d19 --- /dev/null +++ b/internal/fourslash/tests/gen/esModuleInteropFindAllReferences2_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 TestEsModuleInteropFindAllReferences2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @esModuleInterop: true +// @Filename: /a.d.ts +export as namespace abc; +/*1*/export const /*2*/x: number; +// @Filename: /b.ts +import a from "./a"; +a./*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/esModuleInteropFindAllReferences_test.go b/internal/fourslash/tests/gen/esModuleInteropFindAllReferences_test.go new file mode 100644 index 0000000000..439e20c8fa --- /dev/null +++ b/internal/fourslash/tests/gen/esModuleInteropFindAllReferences_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 TestEsModuleInteropFindAllReferences(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @esModuleInterop: true +// @Filename: /abc.d.ts +declare module "a" { + /*1*/export const /*2*/x: number; +} +// @Filename: /b.ts +import a from "a"; +a./*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/explainFilesNodeNextWithTypesReference_test.go b/internal/fourslash/tests/gen/explainFilesNodeNextWithTypesReference_test.go new file mode 100644 index 0000000000..e2824dca1d --- /dev/null +++ b/internal/fourslash/tests/gen/explainFilesNodeNextWithTypesReference_test.go @@ -0,0 +1,52 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExplainFilesNodeNextWithTypesReference(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /node_modules/react-hook-form/package.json +{ + "name": "react-hook-form", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", + "types": "dist/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./dist/index.esm.js", + "require": "./dist/index.cjs.js", + "types": "./dist/index.d.ts" + } + } +} +// @Filename: /node_modules/react-hook-form/dist/index.cjs.js +module.exports = {}; +// @Filename: /node_modules/react-hook-form/dist/index.esm.js +export function useForm() {} +// @Filename: /node_modules/react-hook-form/dist/index.d.ts +/// +export type Foo = React.Whatever; +export function useForm(): any; +// @Filename: /node_modules/react/index.d.ts +declare namespace JSX {} +declare namespace React { export interface Whatever {} } +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "explainFiles": true + } + "files": ["./index.ts"] +} +// @Filename: /index.ts +import { useForm } from "react-hook-form";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferPropertyAccessExpressionHeritageClause_test.go b/internal/fourslash/tests/gen/findAllReferPropertyAccessExpressionHeritageClause_test.go new file mode 100644 index 0000000000..9a75ab2a91 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferPropertyAccessExpressionHeritageClause_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 TestFindAllReferPropertyAccessExpressionHeritageClause(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class B {} +function foo() { + return {/*1*/B: B}; +} +class C extends (foo())./*2*/B {} +class C1 extends foo()./*3*/B {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesDynamicImport1_test.go b/internal/fourslash/tests/gen/findAllReferencesDynamicImport1_test.go new file mode 100644 index 0000000000..a6637254e1 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesDynamicImport1_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 TestFindAllReferencesDynamicImport1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: foo.ts +export function foo() { return "foo"; } +/*1*/import("/*2*/./foo") +/*3*/var x = import("/*4*/./foo")` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFilteringMappedTypeProperty_test.go b/internal/fourslash/tests/gen/findAllReferencesFilteringMappedTypeProperty_test.go new file mode 100644 index 0000000000..49fd167376 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFilteringMappedTypeProperty_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 TestFindAllReferencesFilteringMappedTypeProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const obj = { /*1*/a: 1, b: 2 }; +const filtered: { [P in keyof typeof obj as P extends 'b' ? never : P]: 0; } = { /*2*/a: 0 }; +filtered./*3*/a;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference1_test.go b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference1_test.go new file mode 100644 index 0000000000..45066ee2b4 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference1_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 TestFindAllReferencesFromLinkTagReference1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum E { + /** {@link /**/A} */ + A +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference2_test.go b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference2_test.go new file mode 100644 index 0000000000..c4360783cc --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference2_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 TestFindAllReferencesFromLinkTagReference2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +enum E { + /** {@link /**/Foo} */ + Foo +} +interface Foo { + foo: E.Foo; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference3_test.go b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference3_test.go new file mode 100644 index 0000000000..07525dcfb6 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference3_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 TestFindAllReferencesFromLinkTagReference3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: a.ts +interface Foo { + foo: E.Foo; +} +// @Filename: b.ts +enum E { + /** {@link /**/Foo} */ + Foo +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference4_test.go b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference4_test.go new file mode 100644 index 0000000000..e8ed96c98e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference4_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 TestFindAllReferencesFromLinkTagReference4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum E { + /** {@link /**/B} */ + A, + B +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference5_test.go b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference5_test.go new file mode 100644 index 0000000000..3df4070b1f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesFromLinkTagReference5_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 TestFindAllReferencesFromLinkTagReference5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum E { + /** {@link E./**/A} */ + A +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesImportMeta_test.go b/internal/fourslash/tests/gen/findAllReferencesImportMeta_test.go new file mode 100644 index 0000000000..0158bbc86e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesImportMeta_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 TestFindAllReferencesImportMeta(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// Haha that's so meta! + +let x = import.meta/**/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionNew_test.go b/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionNew_test.go new file mode 100644 index 0000000000..8eba9cbff8 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionNew_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 TestFindAllReferencesJSDocFunctionNew(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: Foo.js +/** @type {function (/*1*/new: string, string): string} */ +var f;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionThis_test.go b/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionThis_test.go new file mode 100644 index 0000000000..b43075c892 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJSDocFunctionThis_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 TestFindAllReferencesJSDocFunctionThis(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: Foo.js +/** @type {function (this: string, string): string} */ +var f = function (s) { return /*0*/this + s; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJsDocTypeLiteral_test.go b/internal/fourslash/tests/gen/findAllReferencesJsDocTypeLiteral_test.go new file mode 100644 index 0000000000..87a75b947b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJsDocTypeLiteral_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 TestFindAllReferencesJsDocTypeLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: foo.js +/** + * @param {object} o - very important! + * @param {string} o.x - a thing, its ok + * @param {number} o.y - another thing + * @param {Object} o.nested - very nested + * @param {boolean} o.nested./*1*/great - much greatness + * @param {number} o.nested.times - twice? probably!?? + */ + function f(o) { return o.nested./*2*/great; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJsOverloadedFunctionParameter_test.go b/internal/fourslash/tests/gen/findAllReferencesJsOverloadedFunctionParameter_test.go new file mode 100644 index 0000000000..d5f3537436 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJsOverloadedFunctionParameter_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 TestFindAllReferencesJsOverloadedFunctionParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: true +// @Filename: foo.js +/** + * @overload + * @param {number} x + * @returns {number} + * + * @overload + * @param {string} x + * @returns {string} + * + * @param {unknown} x + * @returns {unknown} + */ +function foo(x/*1*/) { + return x; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring1_test.go b/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring1_test.go new file mode 100644 index 0000000000..4003bf2968 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring1_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 TestFindAllReferencesJsRequireDestructuring1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @noEmit: true +// @checkJs: true +// @Filename: /X.js +module.exports = { x: 1 }; +// @Filename: /Y.js +const { /*1*/x: { y } } = require("./X");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring_test.go b/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring_test.go new file mode 100644 index 0000000000..2312d73d17 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesJsRequireDestructuring_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 TestFindAllReferencesJsRequireDestructuring(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @noEmit: true +// @checkJs: true +// @Filename: foo.js +module.exports = { + foo: '1' +}; +// @Filename: bar.js +const { /*1*/foo: bar } = require('./foo');` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesLinkTag1_test.go b/internal/fourslash/tests/gen/findAllReferencesLinkTag1_test.go new file mode 100644 index 0000000000..4f3d88c462 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesLinkTag1_test.go @@ -0,0 +1,79 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllReferencesLinkTag1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C/*7*/ { + m/*1*/() { } + n/*2*/ = 1 + static s/*3*/() { } + /** + * {@link m} + * @see {m} + * {@link C.m} + * @see {C.m} + * {@link C#m} + * @see {C#m} + * {@link C.prototype.m} + * @see {C.prototype.m} + */ + p() { } + /** + * {@link n} + * @see {n} + * {@link C.n} + * @see {C.n} + * {@link C#n} + * @see {C#n} + * {@link C.prototype.n} + * @see {C.prototype.n} + */ + q() { } + /** + * {@link s} + * @see {s} + * {@link C.s} + * @see {C.s} + */ + r() { } +} + +interface I/*8*/ { + a/*4*/() + b/*5*/: 1 + /** + * {@link a} + * @see {a} + * {@link I.a} + * @see {I.a} + * {@link I#a} + * @see {I#a} + */ + c() + /** + * {@link b} + * @see {b} + * {@link I.b} + * @see {I.b} + */ + d() +} + +function nestor() { + /** {@link r2} */ + function ref() { } + /** @see {r2} */ + function d3() { } + function r2/*6*/() { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesLinkTag2_test.go b/internal/fourslash/tests/gen/findAllReferencesLinkTag2_test.go new file mode 100644 index 0000000000..e3ee6afd71 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesLinkTag2_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 TestFindAllReferencesLinkTag2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `namespace NPR/*5*/ { + export class Consider/*4*/ { + This/*3*/ = class { + show/*2*/() { } + } + m/*1*/() { } + } + /** + * @see {Consider.prototype.m} + * {@link Consider#m} + * @see {Consider#This#show} + * {@link Consider.This.show} + * @see {NPR.Consider#This#show} + * {@link NPR.Consider.This#show} + * @see {NPR.Consider#This.show} # doesn't parse trailing . + * @see {NPR.Consider.This.show} + */ + export function ref() { } +} +/** + * {@link NPR.Consider#This#show hello hello} + * {@link NPR.Consider.This#show} + * @see {NPR.Consider#This.show} # doesn't parse trailing . + * @see {NPR.Consider.This.show} + */ +export function outerref() { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesLinkTag3_test.go b/internal/fourslash/tests/gen/findAllReferencesLinkTag3_test.go new file mode 100644 index 0000000000..d3e795dcd3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesLinkTag3_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 TestFindAllReferencesLinkTag3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `namespace NPR/*5*/ { + export class Consider/*4*/ { + This/*3*/ = class { + show/*2*/() { } + } + m/*1*/() { } + } + /** + * {@linkcode Consider.prototype.m} + * {@linkplain Consider#m} + * {@linkcode Consider#This#show} + * {@linkplain Consider.This.show} + * {@linkcode NPR.Consider#This#show} + * {@linkplain NPR.Consider.This#show} + * {@linkcode NPR.Consider#This.show} # doesn't parse trailing . + * {@linkcode NPR.Consider.This.show} + */ + export function ref() { } +} +/** + * {@linkplain NPR.Consider#This#show hello hello} + * {@linkplain NPR.Consider.This#show} + * {@linkcode NPR.Consider#This.show} # doesn't parse trailing . + * {@linkcode NPR.Consider.This.show} + */ +export function outerref() { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesNonExistentExportBinding_test.go b/internal/fourslash/tests/gen/findAllReferencesNonExistentExportBinding_test.go new file mode 100644 index 0000000000..606970923a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesNonExistentExportBinding_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 TestFindAllReferencesNonExistentExportBinding(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /tsconfig.json + { "compilerOptions": { "module": "commonjs" } } +// @filename: /bar.ts +import { Foo/**/ } from "./foo"; +// @filename: /foo.ts +export { Foo }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesOfConstructor_badOverload_test.go b/internal/fourslash/tests/gen/findAllReferencesOfConstructor_badOverload_test.go new file mode 100644 index 0000000000..46c30746ef --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesOfConstructor_badOverload_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 TestFindAllReferencesOfConstructor_badOverload(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*1*/constructor(n: number); + /*2*/constructor(){} +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesOfConstructor_test.go b/internal/fourslash/tests/gen/findAllReferencesOfConstructor_test.go new file mode 100644 index 0000000000..ef27ea7925 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesOfConstructor_test.go @@ -0,0 +1,48 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllReferencesOfConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +export class C { + /*0*/constructor(n: number); + /*1*/constructor(); + /*2*/constructor(n?: number){} + static f() { + this.f(); + new this(); + } +} +new C(); +const D = C; +new D(); +// @Filename: b.ts +import { C } from "./a"; +new C(); +// @Filename: c.ts +import { C } from "./a"; +class D extends C { + constructor() { + super(); + super.method(); + } + method() { super(); } +} +class E implements C { + constructor() { super(); } +} +// @Filename: d.ts +import * as a from "./a"; +new a.C(); +class d extends a.C { constructor() { super(); }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesOfJsonModule_test.go b/internal/fourslash/tests/gen/findAllReferencesOfJsonModule_test.go new file mode 100644 index 0000000000..d0c3158d50 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesOfJsonModule_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 TestFindAllReferencesOfJsonModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @resolveJsonModule: true +// @module: commonjs +// @esModuleInterop: true +// @Filename: /foo.ts +/*1*/import /*2*/settings from "./settings.json"; +/*3*/settings; +// @Filename: /settings.json + {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesTripleSlash_test.go b/internal/fourslash/tests/gen/findAllReferencesTripleSlash_test.go new file mode 100644 index 0000000000..eec32bef82 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesTripleSlash_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 TestFindAllReferencesTripleSlash(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /node_modules/@types/globals/index.d.ts +declare const someAmbientGlobal: unknown; +// @Filename: /a.ts +/// +/// +// @Filename: /b.ts +console.log("b.ts"); +// @Filename: /c.js +require("./b"); +require("globals");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesUmdModuleAsGlobalConst_test.go b/internal/fourslash/tests/gen/findAllReferencesUmdModuleAsGlobalConst_test.go new file mode 100644 index 0000000000..c0a0b67b70 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesUmdModuleAsGlobalConst_test.go @@ -0,0 +1,49 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllReferencesUmdModuleAsGlobalConst(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /node_modules/@types/three/three-core.d.ts +export class Vector3 { + constructor(x?: number, y?: number, z?: number); + x: number; + y: number; +} +// @Filename: /node_modules/@types/three/index.d.ts +export * from "./three-core"; +export as namespace /*0*/THREE; +// @Filename: /typings/global.d.ts +import * as _THREE from '/*1*/three'; +declare global { + const /*2*/THREE: typeof _THREE; +} +// @Filename: /src/index.ts +export const a = {}; +let v = new /*3*/THREE.Vector2(); +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "esModuleInterop": true, + "outDir": "./build/js/", + "noImplicitAny": true, + "module": "es6", + "target": "es6", + "allowJs": true, + "skipLibCheck": true, + "lib": ["es2016", "dom"], + "typeRoots": ["node_modules/@types/"], + "types": ["three"] + }, + "files": ["/src/index.ts", "typings/global.d.ts"] +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllReferencesUndefined_test.go b/internal/fourslash/tests/gen/findAllReferencesUndefined_test.go new file mode 100644 index 0000000000..36cbbb2267 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllReferencesUndefined_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 TestFindAllReferencesUndefined(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/**/undefined; + +void undefined; +// @Filename: /b.ts +undefined;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsBadImport_test.go b/internal/fourslash/tests/gen/findAllRefsBadImport_test.go new file mode 100644 index 0000000000..f66312a477 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsBadImport_test.go @@ -0,0 +1,17 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsBadImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import { /*0*/ab as /*1*/cd } from "doesNotExist";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsCatchClause_test.go b/internal/fourslash/tests/gen/findAllRefsCatchClause_test.go new file mode 100644 index 0000000000..ab74baf1b9 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsCatchClause_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 TestFindAllRefsCatchClause(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try { } +catch (/*1*/err) { + /*2*/err; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsClassExpression0_test.go b/internal/fourslash/tests/gen/findAllRefsClassExpression0_test.go new file mode 100644 index 0000000000..7fad3791f3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsClassExpression0_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 TestFindAllRefsClassExpression0(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export = class /*0*/A { + m() { /*1*/A; } +}; +// @Filename: /b.ts +import /*2*/A = require("./a"); +/*3*/A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsClassExpression1_test.go b/internal/fourslash/tests/gen/findAllRefsClassExpression1_test.go new file mode 100644 index 0000000000..67802cafb0 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsClassExpression1_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 TestFindAllRefsClassExpression1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +module.exports = class /*0*/A {}; +// @Filename: /b.js +import /*1*/A = require("./a"); +/*2*/A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsClassExpression2_test.go b/internal/fourslash/tests/gen/findAllRefsClassExpression2_test.go new file mode 100644 index 0000000000..b77f184846 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsClassExpression2_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 TestFindAllRefsClassExpression2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +exports./*0*/A = class {}; +// @Filename: /b.js +import { /*1*/A } from "./a"; +/*2*/A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsClassStaticBlocks_test.go b/internal/fourslash/tests/gen/findAllRefsClassStaticBlocks_test.go new file mode 100644 index 0000000000..00fb8a2839 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsClassStaticBlocks_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 TestFindAllRefsClassStaticBlocks(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class ClassStaticBocks { + static x; + [|[|/*classStaticBocks1*/static|] {}|] + static y; + [|[|/*classStaticBocks2*/static|] {}|] + static y; + [|[|/*classStaticBocks3*/static|] {}|] +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "classStaticBocks1", "classStaticBocks2", "classStaticBocks3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsCommonJsRequire2_test.go b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire2_test.go new file mode 100644 index 0000000000..d8cdf2d191 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire2_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 TestFindAllRefsCommonJsRequire2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +function f() { } +module.exports.f = f +// @Filename: /b.js +const { f } = require('./a') +/**/f` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsCommonJsRequire3_test.go b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire3_test.go new file mode 100644 index 0000000000..5b683392eb --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire3_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 TestFindAllRefsCommonJsRequire3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +function f() { } +module.exports = { f } +// @Filename: /b.js +const { f } = require('./a') +/**/f` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsCommonJsRequire_test.go b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire_test.go new file mode 100644 index 0000000000..03664fd182 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsCommonJsRequire_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 TestFindAllRefsCommonJsRequire(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +function f() { } +export { f } +// @Filename: /b.js +const { f } = require('./a') +/**/f` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsConstructorFunctions_test.go b/internal/fourslash/tests/gen/findAllRefsConstructorFunctions_test.go new file mode 100644 index 0000000000..ddb1dafae3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsConstructorFunctions_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 TestFindAllRefsConstructorFunctions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +function f() { + /*1*/this./*2*/x = 0; +} +f.prototype.setX = function() { + /*3*/this./*4*/x = 1; +} +f.prototype.useX = function() { this./*5*/x; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllRefsDeclareClass_test.go b/internal/fourslash/tests/gen/findAllRefsDeclareClass_test.go new file mode 100644 index 0000000000..56f05b8320 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsDeclareClass_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 TestFindAllRefsDeclareClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/declare class /*2*/C { + static m(): void; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsDefaultImport_test.go b/internal/fourslash/tests/gen/findAllRefsDefaultImport_test.go new file mode 100644 index 0000000000..5cf4a6c3b4 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsDefaultImport_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 TestFindAllRefsDefaultImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export default function /*0*/a() {} +// @Filename: /b.ts +import /*1*/a, * as ns from "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsDefinition_test.go b/internal/fourslash/tests/gen/findAllRefsDefinition_test.go new file mode 100644 index 0000000000..7ad8d39066 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsDefinition_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 TestFindAllRefsDefinition(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const /*1*/x = 0; +/*2*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsDestructureGeneric_test.go b/internal/fourslash/tests/gen/findAllRefsDestructureGeneric_test.go new file mode 100644 index 0000000000..aef26d1b36 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsDestructureGeneric_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 TestFindAllRefsDestructureGeneric(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*0*/x: boolean; +} +declare const i: I; +const { /*1*/x } = i;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsDestructureGetter_test.go b/internal/fourslash/tests/gen/findAllRefsDestructureGetter_test.go new file mode 100644 index 0000000000..49e6de3ace --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsDestructureGetter_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 TestFindAllRefsDestructureGetter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Test { + get /*x0*/x() { return 0; } + + set /*y0*/y(a: number) {} +} +const { /*x1*/x, /*y1*/y } = new Test(); +/*x2*/x; /*y2*/y;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "x0", "x1", "x2", "y0", "y1", "y2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsEnumAsNamespace_test.go b/internal/fourslash/tests/gen/findAllRefsEnumAsNamespace_test.go new file mode 100644 index 0000000000..54d139f812 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsEnumAsNamespace_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 TestFindAllRefsEnumAsNamespace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/enum /*2*/E { A } +let e: /*3*/E.A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsEnumMember_test.go b/internal/fourslash/tests/gen/findAllRefsEnumMember_test.go new file mode 100644 index 0000000000..571021c990 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsEnumMember_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 TestFindAllRefsEnumMember(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum E { /*1*/A, B } +const e: E./*2*/A = E./*3*/A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsExportConstEqualToClass_test.go b/internal/fourslash/tests/gen/findAllRefsExportConstEqualToClass_test.go new file mode 100644 index 0000000000..ef76be32c1 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsExportConstEqualToClass_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 TestFindAllRefsExportConstEqualToClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +class C {} +export const /*0*/D = C; +// @Filename: /b.ts +import { /*1*/D } from "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsExportDefaultClassConstructor_test.go b/internal/fourslash/tests/gen/findAllRefsExportDefaultClassConstructor_test.go new file mode 100644 index 0000000000..a47f3abc59 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsExportDefaultClassConstructor_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 TestFindAllRefsExportDefaultClassConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `export default class { + /*1*/constructor() {} +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsExportEquals_test.go b/internal/fourslash/tests/gen/findAllRefsExportEquals_test.go new file mode 100644 index 0000000000..56070c7f4e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsExportEquals_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 TestFindAllRefsExportEquals(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +type /*0*/T = number; +/*1*/export = /*2*/T; +// @Filename: /b.ts +import /*3*/T = require("/*4*/./a");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsExportNotAtTopLevel_test.go b/internal/fourslash/tests/gen/findAllRefsExportNotAtTopLevel_test.go new file mode 100644 index 0000000000..cfd0178704 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsExportNotAtTopLevel_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 TestFindAllRefsExportNotAtTopLevel(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `{ + /*1*/export const /*2*/x = 0; + /*3*/x; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForComputedProperties2_test.go b/internal/fourslash/tests/gen/findAllRefsForComputedProperties2_test.go new file mode 100644 index 0000000000..ba482ed010 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForComputedProperties2_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 TestFindAllRefsForComputedProperties2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + [/*1*/42](): void; +} + +class C implements I { + [/*2*/42]: any; +} + +var x: I = { + ["/*3*/42"]: function () { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForComputedProperties_test.go b/internal/fourslash/tests/gen/findAllRefsForComputedProperties_test.go new file mode 100644 index 0000000000..4e7d6ac84b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForComputedProperties_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 TestFindAllRefsForComputedProperties(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + ["/*0*/prop1"]: () => void; +} + +class C implements I { + ["/*1*/prop1"]: any; +} + +var x: I = { + ["/*2*/prop1"]: function () { }, +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport01_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport01_test.go new file mode 100644 index 0000000000..c4c2838ec0 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport01_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 TestFindAllRefsForDefaultExport01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/export default class /*2*/DefaultExportedClass { +} + +var x: /*3*/DefaultExportedClass; + +var y = new /*4*/DefaultExportedClass;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport02_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport02_test.go new file mode 100644 index 0000000000..6e7b109f72 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport02_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 TestFindAllRefsForDefaultExport02(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/export default function /*2*/DefaultExportedFunction() { + return /*3*/DefaultExportedFunction; +} + +var x: typeof /*4*/DefaultExportedFunction; + +var y = /*5*/DefaultExportedFunction(); + +/*6*/namespace /*7*/DefaultExportedFunction { +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport03_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport03_test.go new file mode 100644 index 0000000000..85578f9b73 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport03_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 TestFindAllRefsForDefaultExport03(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function /*2*/f() { + return 100; +} + +/*3*/export default /*4*/f; + +var x: typeof /*5*/f; + +var y = /*6*/f(); + +/*7*/namespace /*8*/f { + var local = 100; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport04_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport04_test.go new file mode 100644 index 0000000000..6d4ffd4d02 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport04_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 TestFindAllRefsForDefaultExport04(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +const /*0*/a = 0; +export /*1*/default /*2*/a; +// @Filename: /b.ts +import /*3*/a from "./a"; +/*4*/a;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "2", "1", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport09_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport09_test.go new file mode 100644 index 0000000000..768bf83abb --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport09_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 TestFindAllRefsForDefaultExport09(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /tsconfig.json +{ + "compilerOptions": { + "target": "esnext", + "strict": true, + "outDir": "./out", + "allowSyntheticDefaultImports": true + } +} +// @filename: /a.js +module.exports = []; +// @filename: /b.js +module.exports = 1; +// @filename: /c.ts +export = []; +// @filename: /d.ts +export = 1; +// @filename: /foo.ts +import * as /*0*/a from "./a.js" +import /*1*/aDefault from "./a.js" +import * as /*2*/b from "./b.js" +import /*3*/bDefault from "./b.js" + +import * as /*4*/c from "./c" +import /*5*/cDefault from "./c" +import * as /*6*/d from "./d" +import /*7*/dDefault from "./d"` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3", "4", "5", "6", "7") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport_anonymous_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_anonymous_test.go new file mode 100644 index 0000000000..ce2bdf10e3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_anonymous_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 TestFindAllRefsForDefaultExport_anonymous(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export /*1*/default 1; +// @Filename: /b.ts +import a from "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_test.go new file mode 100644 index 0000000000..e7bbb58786 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultExport_reExport_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 TestFindAllRefsForDefaultExport_reExport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /export.ts +const /*0*/foo = 1; +export default /*1*/foo; +// @Filename: /re-export.ts +export { /*2*/default } from "./export"; +// @Filename: /re-export-dep.ts +import /*3*/fooDefault from "./re-export";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForDefaultKeyword_test.go b/internal/fourslash/tests/gen/findAllRefsForDefaultKeyword_test.go new file mode 100644 index 0000000000..b51c89b4d3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForDefaultKeyword_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 TestFindAllRefsForDefaultKeyword(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +function f(value: string, /*1*/default: string) {} + +const /*2*/default = 1; + +function /*3*/default() {} + +class /*4*/default {} + +const foo = { + /*5*/default: 1 +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForFunctionExpression01_test.go b/internal/fourslash/tests/gen/findAllRefsForFunctionExpression01_test.go new file mode 100644 index 0000000000..66e6fe3155 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForFunctionExpression01_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 TestFindAllRefsForFunctionExpression01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: file1.ts +var foo = /*1*/function /*2*/foo(a = /*3*/foo(), b = () => /*4*/foo) { + /*5*/foo(/*6*/foo, /*7*/foo); +} +// @Filename: file2.ts +/// +foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForImportCallType_test.go b/internal/fourslash/tests/gen/findAllRefsForImportCallType_test.go new file mode 100644 index 0000000000..710406adba --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForImportCallType_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 TestFindAllRefsForImportCallType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /app.ts +export function he/**/llo() {}; +// @Filename: /re-export.ts +export type app = typeof import("./app") +// @Filename: /indirect-use.ts +import type { app } from "./re-export"; +declare const app: app +app.hello();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForImportCall_test.go b/internal/fourslash/tests/gen/findAllRefsForImportCall_test.go new file mode 100644 index 0000000000..2249e2d7a2 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForImportCall_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 TestFindAllRefsForImportCall(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /app.ts +export function he/**/llo() {}; +// @Filename: /re-export.ts +export const services = { app: setup(() => import('./app')) } +function setup(importee: () => Promise): T { return {} as any } +// @Filename: /indirect-use.ts +import("./re-export").then(mod => mod.services.app.hello()); +// @Filename: /direct-use.ts +async function main() { + const mod = await import("./app") + mod.hello(); +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForMappedType_test.go b/internal/fourslash/tests/gen/findAllRefsForMappedType_test.go new file mode 100644 index 0000000000..4045078336 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForMappedType_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 TestFindAllRefsForMappedType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface T { /*1*/a: number }; +type U = { [K in keyof T]: string }; +type V = { [K in keyof U]: boolean }; +const u: U = { a: "" } +const v: V = { a: true }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForObjectLiteralProperties_test.go b/internal/fourslash/tests/gen/findAllRefsForObjectLiteralProperties_test.go new file mode 100644 index 0000000000..611d1a08e8 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForObjectLiteralProperties_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 TestFindAllRefsForObjectLiteralProperties(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var x = { + /*1*/property: {} +}; + +x./*2*/property; + +/*3*/let {/*4*/property: pVar} = x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForObjectSpread_test.go b/internal/fourslash/tests/gen/findAllRefsForObjectSpread_test.go new file mode 100644 index 0000000000..f8ba47b3b5 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForObjectSpread_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 TestFindAllRefsForObjectSpread(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A1 { readonly /*0*/a: string }; +interface A2 { /*1*/a?: number }; +let a1: A1; +let a2: A2; +let a12 = { ...a1, ...a2 }; +a12./*2*/a; +a1./*3*/a;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForRest_test.go b/internal/fourslash/tests/gen/findAllRefsForRest_test.go new file mode 100644 index 0000000000..971a4eed80 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForRest_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 TestFindAllRefsForRest(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Gen { + x: number + /*1*/parent: Gen; + millennial: string; +} +let t: Gen; +var { x, ...rest } = t; +rest./*2*/parent;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForStaticInstanceMethodInheritance_test.go b/internal/fourslash/tests/gen/findAllRefsForStaticInstanceMethodInheritance_test.go new file mode 100644 index 0000000000..83ab0d73e0 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForStaticInstanceMethodInheritance_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 TestFindAllRefsForStaticInstanceMethodInheritance(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X{ + /*0*/foo(): void{} +} + +class Y extends X{ + static /*1*/foo(): void{} +} + +class Z extends Y{ + static /*2*/foo(): void{} + /*3*/foo(): void{} +} + +const x = new X(); +const y = new Y(); +const z = new Z(); +x.foo(); +y.foo(); +z.foo(); +Y.foo(); +Z.foo();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForStaticInstancePropertyInheritance_test.go b/internal/fourslash/tests/gen/findAllRefsForStaticInstancePropertyInheritance_test.go new file mode 100644 index 0000000000..54889cca8e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForStaticInstancePropertyInheritance_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 TestFindAllRefsForStaticInstancePropertyInheritance(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X{ + /*0*/foo:any +} + +class Y extends X{ + static /*1*/foo:any +} + +class Z extends Y{ + static /*2*/foo:any + /*3*/foo:any +} + +const x = new X(); +const y = new Y(); +const z = new Z(); +x./*4*/foo; +y./*5*/foo; +z./*6*/foo; +Y./*7*/foo; +Z./*8*/foo;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3", "4", "5", "6", "7", "8") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForStringLiteralTypes_test.go b/internal/fourslash/tests/gen/findAllRefsForStringLiteralTypes_test.go new file mode 100644 index 0000000000..8fb7209b6e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForStringLiteralTypes_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 TestFindAllRefsForStringLiteralTypes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type Options = "/*1*/option 1" | "option 2"; +let myOption: Options = "/*2*/option 1";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForStringLiteral_test.go b/internal/fourslash/tests/gen/findAllRefsForStringLiteral_test.go new file mode 100644 index 0000000000..b38f4a58c5 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForStringLiteral_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 TestFindAllRefsForStringLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +interface Foo { + property: /**/"foo"; +} +/** + * @type {{ property: "foo"}} + */ +const obj: Foo = { + property: "foo", +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForUMDModuleAlias1_test.go b/internal/fourslash/tests/gen/findAllRefsForUMDModuleAlias1_test.go new file mode 100644 index 0000000000..71dba41593 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForUMDModuleAlias1_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 TestFindAllRefsForUMDModuleAlias1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: 0.d.ts +export function doThing(): string; +export function doTheOtherThing(): void; +/*1*/export as namespace /*2*/myLib; +// @Filename: 1.ts +/// +/*3*/myLib.doThing();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause01_test.go b/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause01_test.go new file mode 100644 index 0000000000..00010a6189 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause01_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 TestFindAllRefsForVariableInExtendsClause01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var /*2*/Base = class { }; +class C extends /*3*/Base { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause02_test.go b/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause02_test.go new file mode 100644 index 0000000000..47debbc4e2 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForVariableInExtendsClause02_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 TestFindAllRefsForVariableInExtendsClause02(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/interface /*2*/Base { } +namespace n { + var Base = class { }; + interface I extends /*3*/Base { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsForVariableInImplementsClause01_test.go b/internal/fourslash/tests/gen/findAllRefsForVariableInImplementsClause01_test.go new file mode 100644 index 0000000000..c0be3ee14a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsForVariableInImplementsClause01_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 TestFindAllRefsForVariableInImplementsClause01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var Base = class { }; +class C extends Base implements /**/Base { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsGlobalThisKeywordInModule_test.go b/internal/fourslash/tests/gen/findAllRefsGlobalThisKeywordInModule_test.go new file mode 100644 index 0000000000..e402507300 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsGlobalThisKeywordInModule_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 TestFindAllRefsGlobalThisKeywordInModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +/*1*/this; +export const c = 1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportEquals_test.go b/internal/fourslash/tests/gen/findAllRefsImportEquals_test.go new file mode 100644 index 0000000000..6d03e7b613 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportEquals_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 TestFindAllRefsImportEquals(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import j = N./**/q; +namespace N { export const q = 0; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsImportType_test.go b/internal/fourslash/tests/gen/findAllRefsImportType_test.go new file mode 100644 index 0000000000..0fd25c7a9c --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsImportType_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 TestFindAllRefsImportType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +module.exports = 0; +/*1*/export type /*2*/N = number; +// @Filename: /b.js +type T = import("./a")./*3*/N;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInClassExpression_test.go b/internal/fourslash/tests/gen/findAllRefsInClassExpression_test.go new file mode 100644 index 0000000000..3dd4551ee9 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInClassExpression_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 TestFindAllRefsInClassExpression(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { /*0*/boom(): void; } +new class C implements I { + /*1*/boom(){} +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsIndexedAccessTypes_test.go b/internal/fourslash/tests/gen/findAllRefsIndexedAccessTypes_test.go new file mode 100644 index 0000000000..b80e51a3d2 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsIndexedAccessTypes_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 TestFindAllRefsIndexedAccessTypes(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*1*/0: number; + /*2*/s: string; +} +interface J { + a: I[/*3*/0], + b: I["/*4*/s"], +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInheritedProperties1_test.go b/internal/fourslash/tests/gen/findAllRefsInheritedProperties1_test.go new file mode 100644 index 0000000000..217a55284e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInheritedProperties1_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 TestFindAllRefsInheritedProperties1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class class1 extends class1 { + /*1*/doStuff() { } + /*2*/propName: string; + } + + var v: class1; + v./*3*/doStuff(); + v./*4*/propName;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInheritedProperties2_test.go b/internal/fourslash/tests/gen/findAllRefsInheritedProperties2_test.go new file mode 100644 index 0000000000..deb24b7092 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInheritedProperties2_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 TestFindAllRefsInheritedProperties2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` interface interface1 extends interface1 { + /*1*/doStuff(): void; // r0 + /*2*/propName: string; // r1 + } + + var v: interface1; + v./*3*/doStuff(); // r2 + v./*4*/propName; // r3` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInheritedProperties3_test.go b/internal/fourslash/tests/gen/findAllRefsInheritedProperties3_test.go new file mode 100644 index 0000000000..dfd454127b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInheritedProperties3_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 TestFindAllRefsInheritedProperties3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class class1 extends class1 { + [|/*0*/doStuff() { }|] + [|/*1*/propName: string;|] + } + interface interface1 extends interface1 { + [|/*2*/doStuff(): void;|] + [|/*3*/propName: string;|] + } + class class2 extends class1 implements interface1 { + [|/*4*/doStuff() { }|] + [|/*5*/propName: string;|] + } + + var v: class2; + v./*6*/doStuff(); + v./*7*/propName;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3", "4", "6", "5", "7") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInheritedProperties4_test.go b/internal/fourslash/tests/gen/findAllRefsInheritedProperties4_test.go new file mode 100644 index 0000000000..dd73c27523 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInheritedProperties4_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 TestFindAllRefsInheritedProperties4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` interface C extends D { + /*0*/prop0: string; + /*1*/prop1: number; + } + + interface D extends C { + /*2*/prop0: string; + } + + var d: D; + d./*3*/prop0; + d./*4*/prop1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "2", "3", "1", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInheritedProperties5_test.go b/internal/fourslash/tests/gen/findAllRefsInheritedProperties5_test.go new file mode 100644 index 0000000000..5bc90a3d9a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInheritedProperties5_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 TestFindAllRefsInheritedProperties5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class C extends D { + /*0*/prop0: string; + /*1*/prop1: number; + } + + class D extends C { + /*2*/prop0: string; + } + + var d: D; + d./*3*/prop0; + d./*4*/prop1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInsideTemplates1_test.go b/internal/fourslash/tests/gen/findAllRefsInsideTemplates1_test.go new file mode 100644 index 0000000000..8ee15f418f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInsideTemplates1_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 TestFindAllRefsInsideTemplates1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var /*2*/x = 10; +var y = ` + "`" + `${ /*3*/x } ${ /*4*/x }` + "`" + `` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInsideTemplates2_test.go b/internal/fourslash/tests/gen/findAllRefsInsideTemplates2_test.go new file mode 100644 index 0000000000..104197f240 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInsideTemplates2_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 TestFindAllRefsInsideTemplates2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function /*2*/f(...rest: any[]) { } +/*3*/f ` + "`" + `${ /*4*/f } ${ /*5*/f }` + "`" + `` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllRefsInsideWithBlock_test.go b/internal/fourslash/tests/gen/findAllRefsInsideWithBlock_test.go new file mode 100644 index 0000000000..5de5e03522 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsInsideWithBlock_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 TestFindAllRefsInsideWithBlock(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var /*2*/x = 0; + +with ({}) { + var y = x; // Reference of x here should not be picked + y++; // also reference for y should be ignored +} + +/*3*/x = /*4*/x + 1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsIsDefinition_test.go b/internal/fourslash/tests/gen/findAllRefsIsDefinition_test.go new file mode 100644 index 0000000000..e4838b2ae9 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsIsDefinition_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 TestFindAllRefsIsDefinition(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare function foo(a: number): number; +declare function foo(a: string): string; +declare function foo/*1*/(a: string | number): string | number; + +function foon(a: number): number; +function foon(a: string): string; +function foon/*2*/(a: string | number): string | number { + return a +} + +foo; foon; + +export const bar/*3*/ = 123; +console.log({ bar }); + +interface IFoo { + foo/*4*/(): void; +} +class Foo implements IFoo { + constructor(n: number) + constructor() + /*5*/constructor(n: number?) { } + foo/*6*/(): void { } + static init() { return new this() } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocImportTag2_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag2_test.go new file mode 100644 index 0000000000..aa70162606 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag2_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 TestFindAllRefsJsDocImportTag2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /component.js +export default class Component { + constructor() { + this.id_ = Math.random(); + } + id() { + return this.id_; + } +} +// @Filename: /spatial-navigation.js +/** @import Component from './component.js' */ + +export class SpatialNavigation { + /** + * @param {Component} component + */ + add(component) {} +} +// @Filename: /player.js +import Component from './component.js'; + +/** + * @extends Component/*1*/ + */ +export class Player extends Component {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocImportTag3_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag3_test.go new file mode 100644 index 0000000000..966773ac8a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag3_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 TestFindAllRefsJsDocImportTag3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /component.js +export class Component { + constructor() { + this.id_ = Math.random(); + } + id() { + return this.id_; + } +} +// @Filename: /spatial-navigation.js +/** @import { Component } from './component.js' */ + +export class SpatialNavigation { + /** + * @param {Component} component + */ + add(component) {} +} +// @Filename: /player.js +import { Component } from './component.js'; + +/** + * @extends Component/*1*/ + */ +export class Player extends Component {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocImportTag4_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag4_test.go new file mode 100644 index 0000000000..2a067d5246 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag4_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 TestFindAllRefsJsDocImportTag4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /component.js +export class Component { + constructor() { + this.id_ = Math.random(); + } + id() { + return this.id_; + } +} +// @Filename: /spatial-navigation.js +/** @import * as C from './component.js' */ + +export class SpatialNavigation { + /** + * @param {C.Component} component + */ + add(component) {} +} +// @Filename: /player.js +import * as C from './component.js'; + +/** + * @extends C/*1*/.Component + */ +export class Player extends Component {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocImportTag5_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag5_test.go new file mode 100644 index 0000000000..06f4862545 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag5_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 TestFindAllRefsJsDocImportTag5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /a.js +export default function /*0*/a() {} +// @Filename: /b.js +/** @import /*1*/a, * as ns from "./a" */` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocImportTag_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag_test.go new file mode 100644 index 0000000000..0608b12346 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocImportTag_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 TestFindAllRefsJsDocImportTag(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJS: true +// @checkJs: true +// @Filename: /b.ts +export interface A { } +// @Filename: /a.js +/** + * @import { A } from "./b"; + */ + +/** + * @param { [|A/**/|] } a + */ +function f(a) {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_js_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_js_test.go new file mode 100644 index 0000000000..711befea3e --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_js_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 TestFindAllRefsJsDocTemplateTag_class_js(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/** @template /*1*/T */ +class C { + constructor() { + /** @type {/*2*/T} */ + this.x = null; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_test.go new file mode 100644 index 0000000000..7fb0d8f215 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_class_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 TestFindAllRefsJsDocTemplateTag_class(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** @template /*1*/T */ +class C {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_js_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_js_test.go new file mode 100644 index 0000000000..f84dd562aa --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_js_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 TestFindAllRefsJsDocTemplateTag_function_js(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/** + * @template /*1*/T + * @return {/*2*/T} + */ +function f() {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_test.go new file mode 100644 index 0000000000..c438850de6 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTemplateTag_function_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 TestFindAllRefsJsDocTemplateTag_function(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** @template /*1*/T */ +function f() {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_js_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_js_test.go new file mode 100644 index 0000000000..1dfa6b2575 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_js_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 TestFindAllRefsJsDocTypeDef_js(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/** /*1*/@typedef {number} /*2*/T */ + +/** + * @return {/*3*/T} + */ +function f(obj) { return 0; } + +/** + * @return {/*4*/T} + */ +function f2(obj) { return 0; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_test.go b/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_test.go new file mode 100644 index 0000000000..d9a9b5de6f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsDocTypeDef_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 TestFindAllRefsJsDocTypeDef(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** @typedef {Object} /*0*/T */ +function foo() {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment2_test.go b/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment2_test.go new file mode 100644 index 0000000000..c2d222384d --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment2_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsJsThisPropertyAssignment2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @noImplicitThis: true +// @Filename: infer.d.ts +export declare function infer(o: { m: Record } & ThisType<{ x: number }>): void; +// @Filename: a.js +import { infer } from "./infer"; +infer({ + m: { + initData() { + this.x = 1; + this./*1*/x; + }, + } +}); +// @Filename: b.ts +import { infer } from "./infer"; +infer({ + m: { + initData() { + this.x = 1; + this./*2*/x; + }, + } +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment_test.go b/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment_test.go new file mode 100644 index 0000000000..14d0eb2438 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsJsThisPropertyAssignment_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsJsThisPropertyAssignment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @noImplicitThis: true +// @Filename: infer.d.ts +export declare function infer(o: { m(): void } & ThisType<{ x: number }>): void; +// @Filename: a.js +import { infer } from "./infer"; +infer({ + m() { + this.x = 1; + this./*1*/x; + }, +}); +// @Filename: b.js +/** + * @template T + * @param {{m(): void} & ThisType<{x: number}>} o + */ +function infer(o) {} +infer({ + m() { + this.x = 2; + this./*2*/x; + }, +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsMappedType_nonHomomorphic_test.go b/internal/fourslash/tests/gen/findAllRefsMappedType_nonHomomorphic_test.go new file mode 100644 index 0000000000..c6adb857ef --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsMappedType_nonHomomorphic_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 TestFindAllRefsMappedType_nonHomomorphic(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +function f(x: { [K in "m"]: number; }) { + x./*1*/m; + x./*2*/m +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsMappedType_test.go b/internal/fourslash/tests/gen/findAllRefsMappedType_test.go new file mode 100644 index 0000000000..4407a74a6f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsMappedType_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 TestFindAllRefsMappedType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface T { /*1*/a: number; } +type U = { readonly [K in keyof T]?: string }; +declare const t: T; +t./*2*/a; +declare const u: U; +u./*3*/a;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsMissingModulesOverlappingSpecifiers_test.go b/internal/fourslash/tests/gen/findAllRefsMissingModulesOverlappingSpecifiers_test.go new file mode 100644 index 0000000000..1ebea78f87 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsMissingModulesOverlappingSpecifiers_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 TestFindAllRefsMissingModulesOverlappingSpecifiers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// https://github.com/microsoft/TypeScript/issues/5551 +import { resolve/*0*/ as resolveUrl } from "idontcare"; +import { resolve/*1*/ } from "whatever";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsModuleDotExports_test.go b/internal/fourslash/tests/gen/findAllRefsModuleDotExports_test.go new file mode 100644 index 0000000000..97fa6533ec --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsModuleDotExports_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 TestFindAllRefsModuleDotExports(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/*1*/const b = require("/*2*/./b"); +// @Filename: /b.js +/*3*/module.exports = 0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsNoImportClause_test.go b/internal/fourslash/tests/gen/findAllRefsNoImportClause_test.go new file mode 100644 index 0000000000..b7e98d676c --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsNoImportClause_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 TestFindAllRefsNoImportClause(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export const /*2*/x = 0; +// @Filename: /b.ts +import "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsNoSubstitutionTemplateLiteralNoCrash1_test.go b/internal/fourslash/tests/gen/findAllRefsNoSubstitutionTemplateLiteralNoCrash1_test.go new file mode 100644 index 0000000000..29e4b95f39 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsNoSubstitutionTemplateLiteralNoCrash1_test.go @@ -0,0 +1,17 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsNoSubstitutionTemplateLiteralNoCrash1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type Test = ` + "`" + `T/*1*/` + "`" + `;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsNonModule_test.go b/internal/fourslash/tests/gen/findAllRefsNonModule_test.go new file mode 100644 index 0000000000..00b5bedb3d --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsNonModule_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 TestFindAllRefsNonModule(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @checkJs: true +// @Filename: /script.ts +console.log("I'm a script!"); +// @Filename: /import.ts +import "./script/*1*/"; +// @Filename: /require.js +require("./script/*2*/"); +console.log("./script/*3*/"); +// @Filename: /tripleSlash.ts +/// +// @Filename: /stringLiteral.ts +console.log("./script");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsNonexistentPropertyNoCrash1_test.go b/internal/fourslash/tests/gen/findAllRefsNonexistentPropertyNoCrash1_test.go new file mode 100644 index 0000000000..d7b93361ba --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsNonexistentPropertyNoCrash1_test.go @@ -0,0 +1,61 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestFindAllRefsNonexistentPropertyNoCrash1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +// @allowJs: true +// @checkJs: true +// @filename: ./src/parser-input.js +export default () => { + let input; + + const parserInput = {}; + + parserInput.currentChar = () => input.charAt(parserInput.i); + + parserInput.end = () => { + const isFinished = parserInput.i >= input.length; + + return { + isFinished, + furthest: parserInput.i, + }; + }; + + return parserInput; +}; +// @filename: ./src/parser.js +import getParserInput from "./parser-input"; + +const Parser = function Parser(context, imports, fileInfo, currentIndex) { + currentIndex = currentIndex || 0; + let parsers; + const parserInput = getParserInput(); + + return { + parserInput, + parsers: (parsers = { + variable: function () { + let name; + + if (parserInput.currentChar() === "/*1*/@") { + return name[1]; + } + }, + }), + }; +}; + +export default Parser;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName01_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName01_test.go new file mode 100644 index 0000000000..9597d43716 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName01_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 TestFindAllRefsObjectBindingElementPropertyName01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*1*/property1: number; + property2: string; +} + +var foo: I; +/*2*/var { /*3*/property1: prop1 } = foo;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName02_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName02_test.go new file mode 100644 index 0000000000..eb786e6c17 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName02_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 TestFindAllRefsObjectBindingElementPropertyName02(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*1*/property1: number; + property2: string; +} + +var foo: I; +/*2*/var { /*3*/property1: {} } = foo;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName03_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName03_test.go new file mode 100644 index 0000000000..ba04d40b18 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName03_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 TestFindAllRefsObjectBindingElementPropertyName03(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*1*/property1: number; + property2: string; +} + +var foo: I; +var [ { property1: prop1 }, { /*2*/property1, property2 } ] = [foo, foo];` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName04_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName04_test.go new file mode 100644 index 0000000000..7c3806cf9a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName04_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 TestFindAllRefsObjectBindingElementPropertyName04(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*0*/property1: number; + property2: string; +} + +function f({ /*1*/property1: p1 }: I, + { /*2*/property1 }: I, + { property1: p2 }) { + + return /*3*/property1 + 1; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName05_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName05_test.go new file mode 100644 index 0000000000..aa13508472 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName05_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 TestFindAllRefsObjectBindingElementPropertyName05(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + property1: number; + property2: string; +} + +function f({ /**/property1: p }, { property1 }) { + let x = property1; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName06_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName06_test.go new file mode 100644 index 0000000000..6a10bc3040 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName06_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 TestFindAllRefsObjectBindingElementPropertyName06(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*0*/property1: number; + property2: string; +} + +var elems: I[]; +for (let { /*1*/property1: p } of elems) { +} +for (let { /*2*/property1 } of elems) { +} +for (var { /*3*/property1: p1 } of elems) { +} +var p2; +for ({ /*4*/property1 : p2 } of elems) { +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "3", "4", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName07_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName07_test.go new file mode 100644 index 0000000000..904acf3d98 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName07_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 TestFindAllRefsObjectBindingElementPropertyName07(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let p, b; + +p, [{ /*1*/a: p, b }] = [{ a: 10, b: true }];` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName10_test.go b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName10_test.go new file mode 100644 index 0000000000..599706f7ec --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsObjectBindingElementPropertyName10_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 TestFindAllRefsObjectBindingElementPropertyName10(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Recursive { + /*1*/next?: Recursive; + value: any; +} + +function f (/*2*/{ /*3*/next: { /*4*/next: x} }: Recursive) { +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOfConstructor_withModifier_test.go b/internal/fourslash/tests/gen/findAllRefsOfConstructor_withModifier_test.go new file mode 100644 index 0000000000..1d6239b1d2 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOfConstructor_withModifier_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 TestFindAllRefsOfConstructor_withModifier(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class X { + public /*0*/constructor() {} +} +var x = new X();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOnDecorators_test.go b/internal/fourslash/tests/gen/findAllRefsOnDecorators_test.go new file mode 100644 index 0000000000..eab0fcdf3b --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOnDecorators_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 TestFindAllRefsOnDecorators(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +/*1*/function /*2*/decorator(target) { + return target; +} +/*3*/decorator(); +// @Filename: b.ts +@/*4*/decorator @/*5*/decorator("again") +class C { + @/*6*/decorator + method() {} +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOnDefinition2_test.go b/internal/fourslash/tests/gen/findAllRefsOnDefinition2_test.go new file mode 100644 index 0000000000..2fbf5d60dc --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOnDefinition2_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 TestFindAllRefsOnDefinition2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: findAllRefsOnDefinition2-import.ts +export module Test{ + + /*1*/export interface /*2*/start { } + + export interface stop { } +} +//@Filename: findAllRefsOnDefinition2.ts +import Second = require("./findAllRefsOnDefinition2-import"); + +var start: Second.Test./*3*/start; +var stop: Second.Test.stop;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOnDefinition_test.go b/internal/fourslash/tests/gen/findAllRefsOnDefinition_test.go new file mode 100644 index 0000000000..aac365995a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOnDefinition_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 TestFindAllRefsOnDefinition(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: findAllRefsOnDefinition-import.ts +export class Test{ + + constructor(){ + + } + + /*1*/public /*2*/start(){ + return this; + } + + public stop(){ + return this; + } +} +//@Filename: findAllRefsOnDefinition.ts +import Second = require("./findAllRefsOnDefinition-import"); + +var second = new Second.Test() +second./*3*/start(); +second.stop();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOnImportAliases_test.go b/internal/fourslash/tests/gen/findAllRefsOnImportAliases_test.go new file mode 100644 index 0000000000..5c7ef13931 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOnImportAliases_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 TestFindAllRefsOnImportAliases(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: a.ts +export class /*0*/Class { +} +//@Filename: b.ts +import { /*1*/Class } from "./a"; + +var c = new /*2*/Class(); +//@Filename: c.ts +export { /*3*/Class } from "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsOnPrivateParameterProperty1_test.go b/internal/fourslash/tests/gen/findAllRefsOnPrivateParameterProperty1_test.go new file mode 100644 index 0000000000..8ffb377062 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsOnPrivateParameterProperty1_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 TestFindAllRefsOnPrivateParameterProperty1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class ABCD { + constructor(private x: number, public y: number, /*1*/private /*2*/z: number) { + } + + func() { + return this./*3*/z; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration1_test.go b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration1_test.go new file mode 100644 index 0000000000..e126ac0101 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration1_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 TestFindAllRefsParameterPropertyDeclaration1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + constructor(private /*1*/privateParam: number) { + let localPrivate = privateParam; + this.privateParam += 10; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration2_test.go b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration2_test.go new file mode 100644 index 0000000000..a8170d7aed --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration2_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 TestFindAllRefsParameterPropertyDeclaration2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + constructor(public /*0*/publicParam: number) { + let localPublic = /*1*/publicParam; + this./*2*/publicParam += 10; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration3_test.go b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration3_test.go new file mode 100644 index 0000000000..b86cb99bfd --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration3_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 TestFindAllRefsParameterPropertyDeclaration3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + constructor(protected /*0*/protectedParam: number) { + let localProtected = /*1*/protectedParam; + this./*2*/protectedParam += 10; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration_inheritance_test.go b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration_inheritance_test.go new file mode 100644 index 0000000000..010fa06c59 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsParameterPropertyDeclaration_inheritance_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 TestFindAllRefsParameterPropertyDeclaration_inheritance(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + constructor(public /*0*/x: string) { + /*1*/x; + } +} +class D extends C { + constructor(public /*2*/x: string) { + super(/*3*/x); + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPrimitiveJsDoc_test.go b/internal/fourslash/tests/gen/findAllRefsPrimitiveJsDoc_test.go new file mode 100644 index 0000000000..671a2db410 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPrimitiveJsDoc_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 TestFindAllRefsPrimitiveJsDoc(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +/** + * @param {/*1*/number} n + * @returns {/*2*/number} + */ +function f(n: /*3*/number): /*4*/number {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPrivateNameAccessors_test.go b/internal/fourslash/tests/gen/findAllRefsPrivateNameAccessors_test.go new file mode 100644 index 0000000000..081721bf96 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPrivateNameAccessors_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 TestFindAllRefsPrivateNameAccessors(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*1*/get /*2*/#foo(){ return 1; } + /*3*/set /*4*/#foo(value: number){ } + constructor() { + this./*5*/#foo(); + } +} +class D extends C { + constructor() { + super() + this.#foo = 20; + } +} +class E { + /*6*/get /*7*/#foo(){ return 1; } + /*8*/set /*9*/#foo(value: number){ } + constructor() { + this./*10*/#foo(); + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPrivateNameMethods_test.go b/internal/fourslash/tests/gen/findAllRefsPrivateNameMethods_test.go new file mode 100644 index 0000000000..b11bbc9837 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPrivateNameMethods_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 TestFindAllRefsPrivateNameMethods(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*1*/#foo(){ } + constructor() { + this./*2*/#foo(); + } +} +class D extends C { + constructor() { + super() + this.#foo = 20; + } +} +class E { + /*3*/#foo(){ } + constructor() { + this./*4*/#foo(); + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPrivateNameProperties_test.go b/internal/fourslash/tests/gen/findAllRefsPrivateNameProperties_test.go new file mode 100644 index 0000000000..7ffd784626 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPrivateNameProperties_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 TestFindAllRefsPrivateNameProperties(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /*1*/#foo = 10; + constructor() { + this./*2*/#foo = 20; + /*3*/#foo in this; + } +} +class D extends C { + constructor() { + super() + this.#foo = 20; + } +} +class E { + /*4*/#foo: number; + constructor() { + this./*5*/#foo = 20; + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findAllRefsPropertyContextuallyTypedByTypeParam01_test.go b/internal/fourslash/tests/gen/findAllRefsPropertyContextuallyTypedByTypeParam01_test.go new file mode 100644 index 0000000000..713e446976 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsPropertyContextuallyTypedByTypeParam01_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 TestFindAllRefsPropertyContextuallyTypedByTypeParam01(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface IFoo { + /*1*/a: string; +} +class C { + method() { + var x: T = { + a: "" + }; + x.a; + } +} + + +var x: IFoo = { + a: "ss" +};` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExport_broken2_test.go b/internal/fourslash/tests/gen/findAllRefsReExport_broken2_test.go new file mode 100644 index 0000000000..960d40e890 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExport_broken2_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 TestFindAllRefsReExport_broken2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export { /*2*/x } from "nonsense";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsReExport_broken_test.go b/internal/fourslash/tests/gen/findAllRefsReExport_broken_test.go new file mode 100644 index 0000000000..8584434558 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsReExport_broken_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 TestFindAllRefsReExport_broken(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export { /*2*/x };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsRedeclaredPropertyInDerivedInterface_test.go b/internal/fourslash/tests/gen/findAllRefsRedeclaredPropertyInDerivedInterface_test.go new file mode 100644 index 0000000000..cdf8e9a389 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsRedeclaredPropertyInDerivedInterface_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 TestFindAllRefsRedeclaredPropertyInDerivedInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +interface A { + readonly /*0*/x: number | string; +} +interface B extends A { + readonly /*1*/x: number; +} +const a: A = { /*2*/x: 0 }; +const b: B = { /*3*/x: 0 };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsRootSymbols_test.go b/internal/fourslash/tests/gen/findAllRefsRootSymbols_test.go new file mode 100644 index 0000000000..0f2448374c --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsRootSymbols_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 TestFindAllRefsRootSymbols(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { /*0*/x: {}; } +interface J { /*1*/x: {}; } +declare const o: (I | J) & { /*2*/x: string }; +o./*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsThisKeywordMultipleFiles_test.go b/internal/fourslash/tests/gen/findAllRefsThisKeywordMultipleFiles_test.go new file mode 100644 index 0000000000..cf7d9e3157 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsThisKeywordMultipleFiles_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 TestFindAllRefsThisKeywordMultipleFiles(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: file1.ts +/*1*/this; /*2*/this; +// @Filename: file2.ts +/*3*/this; +/*4*/this; +// @Filename: file3.ts + ((x = /*5*/this, y) => /*6*/this)(/*7*/this, /*8*/this); + // different 'this' + function f(this) { return this; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8") +} diff --git a/internal/fourslash/tests/gen/findAllRefsThisKeyword_test.go b/internal/fourslash/tests/gen/findAllRefsThisKeyword_test.go new file mode 100644 index 0000000000..71d5da8fc4 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsThisKeyword_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 TestFindAllRefsThisKeyword(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +/*1*/this; +function f(/*2*/this) { + return /*3*/this; + function g(/*4*/this) { return /*5*/this; } +} +class C { + static x() { + /*6*/this; + } + static y() { + () => /*7*/this; + } + constructor() { + /*8*/this; + } + method() { + () => /*9*/this; + } +} +// These are *not* real uses of the 'this' keyword, they are identifiers. +const x = { /*10*/this: 0 } +x./*11*/this;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11") +} diff --git a/internal/fourslash/tests/gen/findAllRefsTypeParameterInMergedInterface_test.go b/internal/fourslash/tests/gen/findAllRefsTypeParameterInMergedInterface_test.go new file mode 100644 index 0000000000..50ae313f12 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsTypeParameterInMergedInterface_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 TestFindAllRefsTypeParameterInMergedInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { a: /*2*/T } +interface I { b: /*4*/T }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsTypedef_importType_test.go b/internal/fourslash/tests/gen/findAllRefsTypedef_importType_test.go new file mode 100644 index 0000000000..d104a0a569 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsTypedef_importType_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 TestFindAllRefsTypedef_importType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +module.exports = 0; +/** /*1*/@typedef {number} /*2*/Foo */ +const dummy = 0; +// @Filename: /b.js +/** @type {import('./a')./*3*/Foo} */ +const x = 0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsTypedef_test.go b/internal/fourslash/tests/gen/findAllRefsTypedef_test.go new file mode 100644 index 0000000000..05e6d1d868 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsTypedef_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 TestFindAllRefsTypedef(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/** + * @typedef I {Object} + * /*1*/@prop /*2*/p {number} + */ + +/** @type {I} */ +let x; +x./*3*/p;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsTypeofImport_test.go b/internal/fourslash/tests/gen/findAllRefsTypeofImport_test.go new file mode 100644 index 0000000000..23711b00fc --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsTypeofImport_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 TestFindAllRefsTypeofImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export const /*2*/x = 0; +declare const a: typeof import("./a"); +a./*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsUnionProperty_test.go b/internal/fourslash/tests/gen/findAllRefsUnionProperty_test.go new file mode 100644 index 0000000000..b9665888ea --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsUnionProperty_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 TestFindAllRefsUnionProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `type T = + | { /*t0*/type: "a", /*p0*/prop: number } + | { /*t1*/type: "b", /*p1*/prop: string }; +const tt: T = { + /*t2*/type: "a", + /*p2*/prop: 0, +}; +declare const t: T; +if (t./*t3*/type === "a") { + t./*t4*/type; +} else { + t./*t5*/type; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "t0", "t1", "t3", "t4", "t5", "t2", "p0", "p1", "p2") +} diff --git a/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols1_test.go b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols1_test.go new file mode 100644 index 0000000000..88834f019f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols1_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 TestFindAllRefsUnresolvedSymbols1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let a: /*a0*/Bar; +let b: /*a1*/Bar; +let c: /*a2*/Bar; +let d: /*b0*/Bar./*c0*/X; +let e: /*b1*/Bar./*c1*/X; +let f: /*b2*/Bar./*d0*/X./*e0*/Y;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "a0", "a1", "a2", "b0", "b1", "b2", "c0", "c1", "d0", "e0") +} diff --git a/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols2_test.go b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols2_test.go new file mode 100644 index 0000000000..03cee6b46c --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols2_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 TestFindAllRefsUnresolvedSymbols2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import { /*a0*/Bar } from "does-not-exist"; + +let a: /*a1*/Bar; +let b: /*a2*/Bar; +let c: /*a3*/Bar; +let d: /*a4*/Bar./*b0*/X; +let e: /*a5*/Bar./*b1*/X; +let f: /*a6*/Bar./*c0*/X./*d0*/Y;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "a0", "a1", "a2", "a3", "a4", "a5", "a6", "b0", "b1", "c0", "d0") +} diff --git a/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols3_test.go b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols3_test.go new file mode 100644 index 0000000000..cbbc67a3c9 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsUnresolvedSymbols3_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 TestFindAllRefsUnresolvedSymbols3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import * as /*a0*/Bar from "does-not-exist"; + +let a: /*a1*/Bar; +let b: /*a2*/Bar; +let c: /*a3*/Bar; +let d: /*a4*/Bar./*b0*/X; +let e: /*a5*/Bar./*b1*/X; +let f: /*a6*/Bar./*c0*/X./*d0*/Y;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "a0", "a1", "a2", "a3", "a4", "a5", "a6", "b0", "b1", "c0", "d0") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames1_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames1_test.go new file mode 100644 index 0000000000..dcee1b535d --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames1_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 TestFindAllRefsWithLeadingUnderscoreNames1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /*1*/public /*2*/_bar() { return 0; } +} + +var x: Foo; +x./*3*/_bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames2_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames2_test.go new file mode 100644 index 0000000000..d71df5ccc7 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames2_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 TestFindAllRefsWithLeadingUnderscoreNames2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /*1*/public /*2*/__bar() { return 0; } +} + +var x: Foo; +x./*3*/__bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames3_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames3_test.go new file mode 100644 index 0000000000..6c46e0d097 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames3_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 TestFindAllRefsWithLeadingUnderscoreNames3(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /*1*/public /*2*/___bar() { return 0; } +} + +var x: Foo; +x./*3*/___bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames4_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames4_test.go new file mode 100644 index 0000000000..c560ef5d0f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames4_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 TestFindAllRefsWithLeadingUnderscoreNames4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /*1*/public /*2*/____bar() { return 0; } +} + +var x: Foo; +x./*3*/____bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames5_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames5_test.go new file mode 100644 index 0000000000..1f7a9e84b0 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames5_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 TestFindAllRefsWithLeadingUnderscoreNames5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + public _bar; + public __bar; + /*1*/public /*2*/___bar; + public ____bar; +} + +var x: Foo; +x._bar; +x.__bar; +x./*3*/___bar; +x.____bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames6_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames6_test.go new file mode 100644 index 0000000000..6c15f525b3 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames6_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 TestFindAllRefsWithLeadingUnderscoreNames6(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + public _bar; + /*1*/public /*2*/__bar; + public ___bar; + public ____bar; +} + +var x: Foo; +x._bar; +x./*3*/__bar; +x.___bar; +x.____bar;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames7_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames7_test.go new file mode 100644 index 0000000000..227ab8092f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames7_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 TestFindAllRefsWithLeadingUnderscoreNames7(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function /*2*/__foo() { + /*3*/__foo(); +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames8_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames8_test.go new file mode 100644 index 0000000000..aaac6e4473 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames8_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 TestFindAllRefsWithLeadingUnderscoreNames8(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `(/*1*/function /*2*/__foo() { + /*3*/__foo(); +})` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames9_test.go b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames9_test.go new file mode 100644 index 0000000000..5612ed5d47 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithLeadingUnderscoreNames9_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 TestFindAllRefsWithLeadingUnderscoreNames9(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `(/*1*/function /*2*/___foo() { + /*3*/___foo(); +})` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment2_test.go b/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment2_test.go new file mode 100644 index 0000000000..0f95e39d3f --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment2_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 TestFindAllRefsWithShorthandPropertyAssignment2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var /*0*/dx = "Foo"; + + module M { export var /*1*/dx; } + module M { + var z = 100; + export var y = { /*2*/dx, z }; + } + M.y./*3*/dx;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment_test.go b/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment_test.go new file mode 100644 index 0000000000..b3d83a5d77 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWithShorthandPropertyAssignment_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 TestFindAllRefsWithShorthandPropertyAssignment(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` var /*0*/name = "Foo"; + + var obj = { /*1*/name }; + var obj1 = { /*2*/name: /*3*/name }; + obj./*4*/name;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "0", "3", "1", "2", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefsWriteAccess_test.go b/internal/fourslash/tests/gen/findAllRefsWriteAccess_test.go new file mode 100644 index 0000000000..7f4ab28ec0 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefsWriteAccess_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 TestFindAllRefsWriteAccess(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Obj { + [` + "`" + `/*1*/num` + "`" + `]: number; +} + +let o: Obj = { + [` + "`" + `num` + "`" + `]: 0 +}; + +o = { + ['num']: 1 +}; + +o['num'] = 2; +o[` + "`" + `num` + "`" + `] = 3; + +o['num']; +o[` + "`" + `num` + "`" + `];` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_js.4_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js.4_test.go new file mode 100644 index 0000000000..0747e8616a --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js.4_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.4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: commonjs +// @allowJs: true +// @checkJs: true +// @Filename: /a.js +/** + * @callback /**/A + * @param {unknown} response + */ + +module.exports = {}; +// @Filename: /b.js +/** @typedef {import("./a").A} A */ ` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} \ No newline at end of file diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_meaningAtLocation_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_meaningAtLocation_test.go new file mode 100644 index 0000000000..c35480b923 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_meaningAtLocation_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 TestFindAllRefs_importType_meaningAtLocation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export type /*2*/T = 0; +/*3*/export const /*4*/T = 0; +// @Filename: /b.ts +const x: import("./a")./*5*/T = 0; +const x: typeof import("./a")./*6*/T = 0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_named_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_named_test.go new file mode 100644 index 0000000000..f7cd7bd8a8 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_named_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 TestFindAllRefs_importType_named(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/*1*/export type /*2*/T = number; +/*3*/export type /*4*/U = string; +// @Filename: /b.ts +const x: import("./a")./*5*/T = 0; +const x: import("./a")./*6*/U = 0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_importType_typeofImport_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_typeofImport_test.go new file mode 100644 index 0000000000..02e749e266 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_typeofImport_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 TestFindAllRefs_importType_typeofImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +export const x = 0; +// @Filename: /b.ts +/*1*/const x: typeof import("/*2*/./a") = { x: 0 }; +/*3*/const y: typeof import("/*4*/./a") = { x: 0 };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findAllRefs_jsEnum_test.go b/internal/fourslash/tests/gen/findAllRefs_jsEnum_test.go new file mode 100644 index 0000000000..8b9635f3b9 --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_jsEnum_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 TestFindAllRefs_jsEnum(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /a.js +/** @enum {string} */ +/*1*/const /*2*/E = { A: "" }; +/*3*/E["A"]; +/** @type {/*4*/E} */ +const e = /*5*/E.A;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5") +} diff --git a/internal/fourslash/tests/gen/findReferencesAcrossMultipleProjects_test.go b/internal/fourslash/tests/gen/findReferencesAcrossMultipleProjects_test.go new file mode 100644 index 0000000000..cc49f492dc --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesAcrossMultipleProjects_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 TestFindReferencesAcrossMultipleProjects(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: a.ts +/*1*/var /*2*/x: number; +//@Filename: b.ts +/// +/*3*/x++; +//@Filename: c.ts +/// +/*4*/x++;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash1_test.go b/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash1_test.go new file mode 100644 index 0000000000..5aceae785e --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash1_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 TestFindReferencesBindingPatternInJsdocNoCrash1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @moduleResolution: node +// @Filename: node_modules/use-query/package.json +{ + "name": "use-query", + "types": "index.d.ts" +} +// @Filename: node_modules/use-query/index.d.ts +declare function useQuery(): { + data: string[]; +}; +// @Filename: node_modules/other/package.json +{ + "name": "other", + "types": "index.d.ts" +} +// @Filename: node_modules/other/index.d.ts +interface BottomSheetModalProps { + /** + * A scrollable node or normal view. + * @type {({ data: any }?) => any} + */ + children: ({ data: any }?) => any; +} +// @Filename: src/index.ts +import { useQuery } from "use-query"; +const { /*1*/data } = useQuery();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash2_test.go b/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash2_test.go new file mode 100644 index 0000000000..1ff230f14a --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesBindingPatternInJsdocNoCrash2_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 TestFindReferencesBindingPatternInJsdocNoCrash2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @moduleResolution: node +// @Filename: node_modules/use-query/package.json +{ + "name": "use-query", + "types": "index.d.ts" +} +// @Filename: node_modules/use-query/index.d.ts +declare function useQuery(): { + data: string[]; +}; +// @Filename: node_modules/use-query/package.json +{ + "name": "other", + "types": "index.d.ts" +} +// @Filename: node_modules/other/index.d.ts +interface BottomSheetModalProps { + /** + * A scrollable node or normal view. + * @type null | (({ data: any }?) => any) + */ + children: null | (({ data: any }?) => any); +} +// @Filename: src/index.ts +import { useQuery } from "use-query"; +const { /*1*/data } = useQuery();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/findReferencesDefinitionDisplayParts_test.go b/internal/fourslash/tests/gen/findReferencesDefinitionDisplayParts_test.go new file mode 100644 index 0000000000..6981eb7c6a --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesDefinitionDisplayParts_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 TestFindReferencesDefinitionDisplayParts(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Gre/*1*/eter { + someFunction() { th/*2*/is; } +} + +type Options = "opt/*3*/ion 1" | "option 2"; +let myOption: Options = "option 1"; + +some/*4*/Label: +break someLabel;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/findReferencesJSXTagName2_test.go b/internal/fourslash/tests/gen/findReferencesJSXTagName2_test.go new file mode 100644 index 0000000000..856fcf2966 --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesJSXTagName2_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 TestFindReferencesJSXTagName2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: index.tsx +/*1*/const /*2*/obj = {Component: () =>
}; +const element = ;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/findReferencesJSXTagName_test.go b/internal/fourslash/tests/gen/findReferencesJSXTagName_test.go new file mode 100644 index 0000000000..c700ef584d --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesJSXTagName_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 TestFindReferencesJSXTagName(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: index.tsx +import { /*1*/SubmissionComp } from "./RedditSubmission" +function displaySubreddit(subreddit: string) { + let components = submissions + .map((value, index) => ); +} +// @Filename: RedditSubmission.ts +export const /*2*/SubmissionComp = (submission: SubmissionProps) => +
;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/findReferencesSeeTagInTs_test.go b/internal/fourslash/tests/gen/findReferencesSeeTagInTs_test.go new file mode 100644 index 0000000000..5748a1f47e --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesSeeTagInTs_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 TestFindReferencesSeeTagInTs(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function doStuffWithStuff/*1*/(stuff: { quantity: number }) {} + +declare const stuff: { quantity: number }; +/** @see {doStuffWithStuff} */ +if (stuff.quantity) {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfArrowFunction_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfArrowFunction_test.go new file mode 100644 index 0000000000..6b0c4c5c13 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfArrowFunction_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 TestGetOccurrencesIsDefinitionOfArrowFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var /*2*/f = x => x + 1; +/*3*/f(12);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfBindingPattern_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfBindingPattern_test.go new file mode 100644 index 0000000000..9145f141a6 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfBindingPattern_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 TestGetOccurrencesIsDefinitionOfBindingPattern(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const { /*1*/x, y } = { /*2*/x: 1, y: 2 }; +const z = /*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfClass_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfClass_test.go new file mode 100644 index 0000000000..7ffcf4d91c --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfClass_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 TestGetOccurrencesIsDefinitionOfClass(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/class /*2*/C { + n: number; + constructor() { + this.n = 12; + } +} +let c = new /*3*/C();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfComputedProperty_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfComputedProperty_test.go new file mode 100644 index 0000000000..e4a3fac0cb --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfComputedProperty_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 TestGetOccurrencesIsDefinitionOfComputedProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let o = { /*1*/["/*2*/foo"]: 12 }; +let y = o./*3*/foo; +let z = o['/*4*/foo'];` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfEnum_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfEnum_test.go new file mode 100644 index 0000000000..9ce1bce0a2 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfEnum_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 TestGetOccurrencesIsDefinitionOfEnum(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/enum /*2*/E { + First, + Second +} +let first = /*3*/E.First;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfExport_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfExport_test.go new file mode 100644 index 0000000000..82ee0347ff --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfExport_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 TestGetOccurrencesIsDefinitionOfExport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: m.ts +export var /*1*/x = 12; +// @Filename: main.ts +import { /*2*/x } from "./m"; +const y = x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfFunction_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfFunction_test.go new file mode 100644 index 0000000000..45b274c359 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfFunction_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 TestGetOccurrencesIsDefinitionOfFunction(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/function /*2*/func(x: number) { +} +/*3*/func(x)` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterfaceClassMerge_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterfaceClassMerge_test.go new file mode 100644 index 0000000000..bf74636cce --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterfaceClassMerge_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 TestGetOccurrencesIsDefinitionOfInterfaceClassMerge(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/interface /*2*/Numbers { + p: number; +} +/*3*/interface /*4*/Numbers { + m: number; +} +/*5*/class /*6*/Numbers { + f(n: number) { + return this.p + this.m + n; + } +} +let i: /*7*/Numbers = new /*8*/Numbers(); +let x = i.f(i.p + i.m);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterface_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterface_test.go new file mode 100644 index 0000000000..163e79261f --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfInterface_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 TestGetOccurrencesIsDefinitionOfInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/interface /*2*/I { + p: number; +} +let i: /*3*/I = { p: 12 };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNamespace_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNamespace_test.go new file mode 100644 index 0000000000..ec47571f6b --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNamespace_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 TestGetOccurrencesIsDefinitionOfNamespace(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/namespace /*2*/Numbers { + export var n = 12; +} +let x = /*3*/Numbers.n + 1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNumberNamedProperty_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNumberNamedProperty_test.go new file mode 100644 index 0000000000..00d2aa3c82 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfNumberNamedProperty_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 TestGetOccurrencesIsDefinitionOfNumberNamedProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let o = { /*1*/1: 12 }; +let y = o[/*2*/1];` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfParameter_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfParameter_test.go new file mode 100644 index 0000000000..db7530e644 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfParameter_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 TestGetOccurrencesIsDefinitionOfParameter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f(/*1*/x: number) { + return /*2*/x + 1 +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfStringNamedProperty_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfStringNamedProperty_test.go new file mode 100644 index 0000000000..fafef8d456 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfStringNamedProperty_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 TestGetOccurrencesIsDefinitionOfStringNamedProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let o = { /*1*/"/*2*/x": 12 }; +let y = o./*3*/x;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfTypeAlias_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfTypeAlias_test.go new file mode 100644 index 0000000000..d52e14fa09 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfTypeAlias_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 TestGetOccurrencesIsDefinitionOfTypeAlias(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/type /*2*/Alias= number; +let n: /*3*/Alias = 12;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfVariable_test.go b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfVariable_test.go new file mode 100644 index 0000000000..4afb5bf9a1 --- /dev/null +++ b/internal/fourslash/tests/gen/getOccurrencesIsDefinitionOfVariable_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 TestGetOccurrencesIsDefinitionOfVariable(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/*1*/var /*2*/x = 0; +var assignmentRightHandSide = /*3*/x; +var assignmentRightHandSide2 = 1 + /*4*/x; + +/*5*/x = 1; +/*6*/x = /*7*/x + /*8*/x; + +/*9*/x == 1; +/*10*/x <= 1; + +var preIncrement = ++/*11*/x; +var postIncrement = /*12*/x++; +var preDecrement = --/*13*/x; +var postDecrement = /*14*/x--; + +/*15*/x += 1; +/*16*/x <<= 1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16") +} diff --git a/internal/fourslash/tests/gen/isDefinitionAcrossGlobalProjects_test.go b/internal/fourslash/tests/gen/isDefinitionAcrossGlobalProjects_test.go new file mode 100644 index 0000000000..cdcdc26f23 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionAcrossGlobalProjects_test.go @@ -0,0 +1,97 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIsDefinitionAcrossGlobalProjects(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/a/index.ts +namespace NS { + export function /*1*/FA() { + FB(); + } +} + +interface /*2*/I { + /*3*/FA(); +} + +const ia: I = { + FA() { }, + FB() { }, + FC() { }, + }; +// @Filename: /home/src/workspaces/project/a/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "references": [ + { "path": "../b" }, + { "path": "../c" }, + ], + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/b/index.ts +namespace NS { + export function /*4*/FB() {} +} + +interface /*5*/I { + /*6*/FB(); +} + +const ib: I = { FB() {} }; +// @Filename: /home/src/workspaces/project/b/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/c/index.ts +namespace NS { + export function /*7*/FC() {} +} + +interface /*8*/I { + /*9*/FC(); +} + +const ic: I = { FC() {} }; +// @Filename: /home/src/workspaces/project/c/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/tsconfig.json +{ + "compilerOptions": { + "composite": true, + }, + "references": [ + { "path": "a" }, + ], + "files": [] +} +// @Filename: /home/src/workspaces/project/tsconfig.settings.json +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "declarationMap": true, + "module": "none", + "emitDeclarationOnly": true, + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8", "9") +} diff --git a/internal/fourslash/tests/gen/isDefinitionAcrossModuleProjects_test.go b/internal/fourslash/tests/gen/isDefinitionAcrossModuleProjects_test.go new file mode 100644 index 0000000000..98a8ee14d6 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionAcrossModuleProjects_test.go @@ -0,0 +1,136 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIsDefinitionAcrossModuleProjects(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/a/index.ts +import { NS } from "../b"; +import { I } from "../c"; + +declare module "../b" { + export namespace NS { + export function /*1*/FA(); + } +} + +declare module "../c" { + export interface /*2*/I { + /*3*/FA(); + } +} + +const ia: I = { + FA: NS.FA, + FC() { }, +}; +// @Filename: /home/src/workspaces/project/a/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "references": [ + { "path": "../b" }, + { "path": "../c" }, + ], + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/a2/index.ts +import { NS } from "../b"; +import { I } from "../c"; + +declare module "../b" { + export namespace NS { + export function /*4*/FA(); + } +} + +declare module "../c" { + export interface /*5*/I { + /*6*/FA(); + } +} + +const ia: I = { + FA: NS.FA, + FC() { }, +}; +// @Filename: /home/src/workspaces/project/a2/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "references": [ + { "path": "../b" }, + { "path": "../c" }, + ], + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/b/index.ts +export namespace NS { + export function /*7*/FB() {} +} + +export interface /*8*/I { + /*9*/FB(); +} + +const ib: I = { FB() {} }; +// @Filename: /home/src/workspaces/project/b/other.ts +export const Other = 1; +// @Filename: /home/src/workspaces/project/b/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "files": [ + "index.ts", + "other.ts", + ], +} +// @Filename: /home/src/workspaces/project/c/index.ts +export namespace NS { + export function /*10*/FC() {} +} + +export interface /*11*/I { + /*12*/FC(); +} + +const ic: I = { FC() {} }; +// @Filename: /home/src/workspaces/project/c/tsconfig.json +{ + "extends": "../tsconfig.settings.json", + "files": [ + "index.ts", + ], +} +// @Filename: /home/src/workspaces/project/tsconfig.json +{ + "compilerOptions": { + "composite": true, + }, + "references": [ + { "path": "a" }, + { "path": "a2" }, + ], + "files": [] +} +// @Filename: /home/src/workspaces/project/tsconfig.settings.json +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "declarationMap": true, + "module": "CommonJS", + "emitDeclarationOnly": true, + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12") +} diff --git a/internal/fourslash/tests/gen/isDefinitionInterfaceImplementation_test.go b/internal/fourslash/tests/gen/isDefinitionInterfaceImplementation_test.go new file mode 100644 index 0000000000..4663706823 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionInterfaceImplementation_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 TestIsDefinitionInterfaceImplementation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface I { + /*1*/M(): void; +} + +class C implements I { + /*2*/M() { } +} + +({} as I).M(); +({} as C).M();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/isDefinitionOverloads_test.go b/internal/fourslash/tests/gen/isDefinitionOverloads_test.go new file mode 100644 index 0000000000..0ec53d8590 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionOverloads_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 TestIsDefinitionOverloads(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function /*1*/f(x: number): void; +function /*2*/f(x: string): void; +function /*3*/f(x: number | string) { } + +f(1); +f("a");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/isDefinitionShorthandProperty_test.go b/internal/fourslash/tests/gen/isDefinitionShorthandProperty_test.go new file mode 100644 index 0000000000..743326da9e --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionShorthandProperty_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 TestIsDefinitionShorthandProperty(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `const /*1*/x = 1; +const y: { /*2*/x: number } = { /*3*/x };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} diff --git a/internal/fourslash/tests/gen/isDefinitionSingleImport_test.go b/internal/fourslash/tests/gen/isDefinitionSingleImport_test.go new file mode 100644 index 0000000000..3d6b6948f9 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionSingleImport_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 TestIsDefinitionSingleImport(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: a.ts +export function /*1*/f() {} +// @filename: b.ts +import { /*2*/f } from "./a";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/isDefinitionSingleReference_test.go b/internal/fourslash/tests/gen/isDefinitionSingleReference_test.go new file mode 100644 index 0000000000..bcbeb76bb9 --- /dev/null +++ b/internal/fourslash/tests/gen/isDefinitionSingleReference_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 TestIsDefinitionSingleReference(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function /*1*/f() {} +/*2*/f();` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") +} diff --git a/internal/fourslash/tests/gen/jsdocLink_findAllReferences1_test.go b/internal/fourslash/tests/gen/jsdocLink_findAllReferences1_test.go new file mode 100644 index 0000000000..8a6ba41c5b --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocLink_findAllReferences1_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 TestJsdocLink_findAllReferences1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A/**/ {} +/** + * {@link A()} is ok + */ +declare const a: A` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/jsdocSatisfiesTagFindAllReferences_test.go b/internal/fourslash/tests/gen/jsdocSatisfiesTagFindAllReferences_test.go new file mode 100644 index 0000000000..9a41f9fa98 --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocSatisfiesTagFindAllReferences_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 TestJsdocSatisfiesTagFindAllReferences(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noEmit: true +// @allowJS: true +// @checkJs: true +// @filename: /a.js +/** + * @typedef {Object} T + * @property {number} a + */ + +/** @satisfies {/**/T} comment */ +const foo = { a: 1 };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/jsdocThrowsTag_findAllReferences_test.go b/internal/fourslash/tests/gen/jsdocThrowsTag_findAllReferences_test.go new file mode 100644 index 0000000000..79ff8af1a3 --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocThrowsTag_findAllReferences_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 TestJsdocThrowsTag_findAllReferences(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class /**/E extends Error {} +/** + * @throws {E} + */ +function f() {}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning0_test.go b/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning0_test.go new file mode 100644 index 0000000000..c5ff10b84b --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning0_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 TestJsdocTypedefTagSemanticMeaning0(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: a.js +/** /*1*/@typedef {number} /*2*/T */ +/*3*/const /*4*/T = 1; +/** @type {/*5*/T} */ +const n = /*6*/T;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4", "5", "6") +} diff --git a/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning1_test.go b/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning1_test.go new file mode 100644 index 0000000000..23ab8a1d1c --- /dev/null +++ b/internal/fourslash/tests/gen/jsdocTypedefTagSemanticMeaning1_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 TestJsdocTypedefTagSemanticMeaning1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: a.js +/** @typedef {number} */ +/*1*/const /*2*/T = 1; +/** @type {/*3*/T} */ +const n = /*4*/T;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2", "3", "4") +} diff --git a/internal/fourslash/tests/gen/jsxFindAllReferencesOnRuntimeImportWithPaths1_test.go b/internal/fourslash/tests/gen/jsxFindAllReferencesOnRuntimeImportWithPaths1_test.go new file mode 100644 index 0000000000..83a9c2d649 --- /dev/null +++ b/internal/fourslash/tests/gen/jsxFindAllReferencesOnRuntimeImportWithPaths1_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 TestJsxFindAllReferencesOnRuntimeImportWithPaths1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: project/src/foo.ts +import * as x from /**/"@foo/dir/jsx-runtime"; +// @Filename: project/src/bar.tsx +export default
; +// @Filename: project/src/baz.tsx +export default <>; +// @Filename: project/src/bam.tsx +export default