diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 9be89da690..0e084ab482 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -9,23 +9,29 @@ Most of our development takes place in the `internal` directory, and most behavi Most development on the codebase is in Go. Standard Go commands and practices apply, but we primarily use a tool called `hereby` to build, run tests, and other tasks. -Feel free to install `hereby` globally (`npm install -g hereby`) if it is easier, and run `hereby --list` to see all available commands. +Run `npx hereby --list` to see all available commands. ```sh -hereby build # Build the project -hereby test # Run tests -hereby format # Format the code -hereby lint # Run linters +npx hereby build # Build the project +npx hereby test # Run tests +npx hereby format # Format the code +npx hereby lint # Run linters + +# To run a specific compiler test: +go test -run='TestSubmodule/' ./internal/testrunner # For submodule tests in _submodules/TypeScript +go test -run='TestLocal/' ./internal/testrunner # For local tests in testdata/tests/cases ``` -Always make sure code is formatted, linted, and tested before sending a pull request. - +Always make sure code is formatted, linted, and tested before sending a pull request. + ## Compiler Features, Fixes, and Tests When fixing a bug or implementing a new feature, at least one minimal test case should always be added in advance to verify the fix. This project primarily uses snapshot/baseline/golden tests rather than unit tests. New compiler tests are written in `.ts`/`.tsx` files in the directory `testdata/tests/cases/compiler/`, and are written in the following format: +**Note:** Issues with editor features cannot be tested with compiler tests in `testdata/tests/cases/`. Editor functionality requires integration testing with the language server. + ```ts // @target: esnext // @module: preserve @@ -79,6 +85,12 @@ It is ideal to implement features and fixes in the following order, and commit c It is fine to implement more and more of a feature across commits, but be sure to update baselines every time so that reviewers can measure progress. +## Code Porting Reference + +The code in `internal` is ported from the code in `_submodules/TypeScript`. +When implementing features or fixing bugs, those files should be searched for similar functions when code is either missing or potentially wrong. +The TypeScript submodule serves as the reference implementation for behavior and functionality. + # Other Instructions - Do not add or change existing dependencies unless asked to. diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 26759ed3f1..065e58c19f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -48,7 +48,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/init@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 with: config-file: ./.github/codeql/codeql-configuration.yml # Override language selection by uncommenting this and choosing your languages @@ -58,7 +58,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below). - name: Autobuild - uses: github/codeql-action/autobuild@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/autobuild@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -72,4 +72,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/analyze@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 1aef70e6c2..222d1f5108 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -23,8 +23,13 @@ jobs: - uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable - uses: ./.github/actions/setup-go with: + # Updated to 1.25.0-rc.1 to improve compilation time + go-version: '>=1.25.0-rc.1' cache-name: copilot-setup-steps - run: npm i -g @playwright/mcp@0.0.28 - run: npm ci # pull dprint caches before network access is blocked - run: npx hereby check:format || true + # cache build and lint operations + - run: npx hereby build || true + - run: npx hereby lint || true diff --git a/.golangci.yml b/.golangci.yml index 373793aa33..1db330cfe6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -63,6 +63,10 @@ linters: type: module exclusions: + rules: + - path: internal/fourslash/tests/gen/ + linters: misspell + presets: - comments - std-error-handling diff --git a/cmd/tsgo/api.go b/cmd/tsgo/api.go index 702ce143a2..9438c39115 100644 --- a/cmd/tsgo/api.go +++ b/cmd/tsgo/api.go @@ -26,7 +26,6 @@ func runAPI(args []string) int { Out: os.Stdout, Err: os.Stderr, Cwd: *cwd, - NewLine: "\n", DefaultLibraryPath: defaultLibraryPath, }) diff --git a/cmd/tsgo/sys.go b/cmd/tsgo/sys.go index cb8ce52222..cfdafdd209 100644 --- a/cmd/tsgo/sys.go +++ b/cmd/tsgo/sys.go @@ -4,11 +4,9 @@ import ( "fmt" "io" "os" - "runtime" "time" "github.com/microsoft/typescript-go/internal/bundled" - "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/execute" "github.com/microsoft/typescript-go/internal/tspath" "github.com/microsoft/typescript-go/internal/vfs" @@ -19,7 +17,6 @@ type osSys struct { writer io.Writer fs vfs.FS defaultLibraryPath string - newLine string cwd string start time.Time } @@ -44,10 +41,6 @@ func (s *osSys) GetCurrentDirectory() string { return s.cwd } -func (s *osSys) NewLine() string { - return s.newLine -} - func (s *osSys) Writer() io.Writer { return s.writer } @@ -69,7 +62,6 @@ func newSystem() *osSys { fs: bundled.WrapFS(osvfs.FS()), defaultLibraryPath: bundled.LibPath(), writer: os.Stdout, - newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"), start: time.Now(), } } diff --git a/internal/api/api.go b/internal/api/api.go index b522371125..1c71476794 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -111,11 +111,6 @@ func (api *API) Trace(s string) { api.options.Logger.Info(s) } -// NewLine implements ProjectHost. -func (api *API) NewLine() string { - return api.host.NewLine() -} - // PositionEncoding implements ProjectHost. func (api *API) PositionEncoding() lsproto.PositionEncodingKind { return lsproto.PositionEncodingKindUTF8 diff --git a/internal/api/host.go b/internal/api/host.go index 83d45a8c60..21136ac5d9 100644 --- a/internal/api/host.go +++ b/internal/api/host.go @@ -6,5 +6,4 @@ type APIHost interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string } diff --git a/internal/api/server.go b/internal/api/server.go index e6c5a6d575..afc558bd56 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -61,7 +61,6 @@ type ServerOptions struct { Out io.Writer Err io.Writer Cwd string - NewLine string DefaultLibraryPath string } @@ -98,7 +97,6 @@ func NewServer(options *ServerOptions) *Server { w: bufio.NewWriter(options.Out), stderr: options.Err, cwd: options.Cwd, - newLine: options.NewLine, fs: bundled.WrapFS(osvfs.FS()), defaultLibraryPath: options.DefaultLibraryPath, } @@ -126,11 +124,6 @@ func (s *Server) GetCurrentDirectory() string { return s.cwd } -// NewLine implements APIHost. -func (s *Server) NewLine() string { - return s.newLine -} - func (s *Server) Run() error { for { messageType, method, payload, err := s.readRequest("") diff --git a/internal/ast/ast.go b/internal/ast/ast.go index bbaba269cf..0d3f3cd264 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -49,41 +49,55 @@ func visitModifiers(v Visitor, modifiers *ModifierList) bool { // NodeFactory type NodeFactory struct { - hooks NodeFactoryHooks - binaryExpressionPool core.Pool[BinaryExpression] - blockPool core.Pool[Block] - callExpressionPool core.Pool[CallExpression] - expressionStatementPool core.Pool[ExpressionStatement] - functionDeclarationPool core.Pool[FunctionDeclaration] - functionTypeNodePool core.Pool[FunctionTypeNode] - identifierPool core.Pool[Identifier] - ifStatementPool core.Pool[IfStatement] - interfaceDeclarationPool core.Pool[InterfaceDeclaration] - jsdocPool core.Pool[JSDoc] - jsdocTextPool core.Pool[JSDocText] - keywordExpressionPool core.Pool[KeywordExpression] - keywordTypeNodePool core.Pool[KeywordTypeNode] - literalTypeNodePool core.Pool[LiteralTypeNode] - methodSignatureDeclarationPool core.Pool[MethodSignatureDeclaration] - modifierListPool core.Pool[ModifierList] - nodeListPool core.Pool[NodeList] - numericLiteralPool core.Pool[NumericLiteral] - parameterDeclarationPool core.Pool[ParameterDeclaration] - parenthesizedExpressionPool core.Pool[ParenthesizedExpression] - parenthesizedTypeNodePool core.Pool[ParenthesizedTypeNode] - prefixUnaryExpressionPool core.Pool[PrefixUnaryExpression] - propertyAccessExpressionPool core.Pool[PropertyAccessExpression] - propertyAssignmentPool core.Pool[PropertyAssignment] - propertySignatureDeclarationPool core.Pool[PropertySignatureDeclaration] - returnStatementPool core.Pool[ReturnStatement] - stringLiteralPool core.Pool[StringLiteral] - tokenPool core.Pool[Token] - typeLiteralNodePool core.Pool[TypeLiteralNode] - typeReferenceNodePool core.Pool[TypeReferenceNode] - unionTypeNodePool core.Pool[UnionTypeNode] - variableDeclarationListPool core.Pool[VariableDeclarationList] - variableDeclarationPool core.Pool[VariableDeclaration] - variableStatementPool core.Pool[VariableStatement] + hooks NodeFactoryHooks + arrayTypeNodePool core.Pool[ArrayTypeNode] + binaryExpressionPool core.Pool[BinaryExpression] + blockPool core.Pool[Block] + callExpressionPool core.Pool[CallExpression] + conditionalExpressionPool core.Pool[ConditionalExpression] + constructSignatureDeclarationPool core.Pool[ConstructSignatureDeclaration] + elementAccessExpressionPool core.Pool[ElementAccessExpression] + expressionStatementPool core.Pool[ExpressionStatement] + expressionWithTypeArgumentsPool core.Pool[ExpressionWithTypeArguments] + functionDeclarationPool core.Pool[FunctionDeclaration] + functionTypeNodePool core.Pool[FunctionTypeNode] + heritageClausePool core.Pool[HeritageClause] + identifierPool core.Pool[Identifier] + ifStatementPool core.Pool[IfStatement] + importSpecifierPool core.Pool[ImportSpecifier] + indexedAccessTypeNodePool core.Pool[IndexedAccessTypeNode] + interfaceDeclarationPool core.Pool[InterfaceDeclaration] + jsdocDeprecatedTagPool core.Pool[JSDocDeprecatedTag] + jsdocParameterOrPropertyTagPool core.Pool[JSDocParameterOrPropertyTag] + jsdocPool core.Pool[JSDoc] + jsdocTextPool core.Pool[JSDocText] + jsdocUnknownTagPool core.Pool[JSDocUnknownTag] + keywordExpressionPool core.Pool[KeywordExpression] + keywordTypeNodePool core.Pool[KeywordTypeNode] + literalTypeNodePool core.Pool[LiteralTypeNode] + methodSignatureDeclarationPool core.Pool[MethodSignatureDeclaration] + modifierListPool core.Pool[ModifierList] + nodeListPool core.Pool[NodeList] + numericLiteralPool core.Pool[NumericLiteral] + parameterDeclarationPool core.Pool[ParameterDeclaration] + parenthesizedExpressionPool core.Pool[ParenthesizedExpression] + parenthesizedTypeNodePool core.Pool[ParenthesizedTypeNode] + prefixUnaryExpressionPool core.Pool[PrefixUnaryExpression] + propertyAccessExpressionPool core.Pool[PropertyAccessExpression] + propertyAssignmentPool core.Pool[PropertyAssignment] + propertySignatureDeclarationPool core.Pool[PropertySignatureDeclaration] + returnStatementPool core.Pool[ReturnStatement] + stringLiteralPool core.Pool[StringLiteral] + tokenPool core.Pool[Token] + typeAliasDeclarationPool core.Pool[TypeAliasDeclaration] + typeLiteralNodePool core.Pool[TypeLiteralNode] + typeOperatorNodePool core.Pool[TypeOperatorNode] + typeParameterDeclarationPool core.Pool[TypeParameterDeclaration] + typeReferenceNodePool core.Pool[TypeReferenceNode] + unionTypeNodePool core.Pool[UnionTypeNode] + variableDeclarationListPool core.Pool[VariableDeclarationList] + variableDeclarationPool core.Pool[VariableDeclaration] + variableStatementPool core.Pool[VariableStatement] nodeCount int textCount int @@ -309,6 +323,12 @@ func (n *Node) Text() string { return n.AsRegularExpressionLiteral().Text case KindJSDocText: return strings.Join(n.AsJSDocText().text, "") + case KindJSDocLink: + return strings.Join(n.AsJSDocLink().text, "") + case KindJSDocLinkCode: + return strings.Join(n.AsJSDocLinkCode().text, "") + case KindJSDocLinkPlain: + return strings.Join(n.AsJSDocLinkPlain().text, "") } panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data)) } @@ -2174,7 +2194,7 @@ type TypeParameterDeclaration struct { } func (f *NodeFactory) NewTypeParameterDeclaration(modifiers *ModifierList, name *IdentifierNode, constraint *TypeNode, defaultType *TypeNode) *Node { - data := &TypeParameterDeclaration{} + data := f.typeParameterDeclarationPool.New() data.modifiers = modifiers data.name = name data.Constraint = constraint @@ -3693,7 +3713,7 @@ type HeritageClause struct { } func (f *NodeFactory) NewHeritageClause(token Kind, types *NodeList) *Node { - data := &HeritageClause{} + data := f.heritageClausePool.New() data.Token = token data.Types = types return f.newNode(KindHeritageClause, data) @@ -3798,7 +3818,7 @@ type TypeAliasDeclaration struct { } func (f *NodeFactory) newTypeAliasOrJSTypeAliasDeclaration(kind Kind, modifiers *ModifierList, name *IdentifierNode, typeParameters *NodeList, typeNode *TypeNode) *Node { - data := &TypeAliasDeclaration{} + data := f.typeAliasDeclarationPool.New() data.modifiers = modifiers data.name = name data.TypeParameters = typeParameters @@ -4240,7 +4260,7 @@ type ImportSpecifier struct { } func (f *NodeFactory) NewImportSpecifier(isTypeOnly bool, propertyName *ModuleExportName, name *IdentifierNode) *Node { - data := &ImportSpecifier{} + data := f.importSpecifierPool.New() data.IsTypeOnly = isTypeOnly data.PropertyName = propertyName data.name = name @@ -4895,7 +4915,7 @@ type ConstructSignatureDeclaration struct { } func (f *NodeFactory) NewConstructSignatureDeclaration(typeParameters *NodeList, parameters *NodeList, returnType *TypeNode) *Node { - data := &ConstructSignatureDeclaration{} + data := f.constructSignatureDeclarationPool.New() data.TypeParameters = typeParameters data.Parameters = parameters data.Type = returnType @@ -6009,7 +6029,7 @@ type ConditionalExpression struct { } func (f *NodeFactory) NewConditionalExpression(condition *Expression, questionToken *TokenNode, whenTrue *Expression, colonToken *TokenNode, whenFalse *Expression) *Node { - data := &ConditionalExpression{} + data := f.conditionalExpressionPool.New() data.Condition = condition data.QuestionToken = questionToken data.WhenTrue = whenTrue @@ -6116,7 +6136,7 @@ type ElementAccessExpression struct { } func (f *NodeFactory) NewElementAccessExpression(expression *Expression, questionDotToken *TokenNode, argumentExpression *Expression, flags NodeFlags) *Node { - data := &ElementAccessExpression{} + data := f.elementAccessExpressionPool.New() data.Expression = expression data.QuestionDotToken = questionDotToken data.ArgumentExpression = argumentExpression @@ -7157,7 +7177,7 @@ type TypeOperatorNode struct { } func (f *NodeFactory) NewTypeOperatorNode(operator Kind, typeNode *TypeNode) *Node { - data := &TypeOperatorNode{} + data := f.typeOperatorNodePool.New() data.Operator = operator data.Type = typeNode return f.newNode(KindTypeOperator, data) @@ -7230,7 +7250,7 @@ type ArrayTypeNode struct { } func (f *NodeFactory) NewArrayTypeNode(elementType *TypeNode) *Node { - data := &ArrayTypeNode{} + data := f.arrayTypeNodePool.New() data.ElementType = elementType return f.newNode(KindArrayType, data) } @@ -7263,7 +7283,7 @@ type IndexedAccessTypeNode struct { } func (f *NodeFactory) NewIndexedAccessTypeNode(objectType *TypeNode, indexType *TypeNode) *Node { - data := &IndexedAccessTypeNode{} + data := f.indexedAccessTypeNodePool.New() data.ObjectType = objectType data.IndexType = indexType return f.newNode(KindIndexedAccessType, data) @@ -7340,7 +7360,7 @@ type ExpressionWithTypeArguments struct { } func (f *NodeFactory) NewExpressionWithTypeArguments(expression *Expression, typeArguments *NodeList) *Node { - data := &ExpressionWithTypeArguments{} + data := f.expressionWithTypeArgumentsPool.New() data.Expression = expression data.TypeArguments = typeArguments return f.newNode(KindExpressionWithTypeArguments, data) @@ -9195,7 +9215,7 @@ type JSDocUnknownTag struct { } func (f *NodeFactory) NewJSDocUnknownTag(tagName *IdentifierNode, comment *NodeList) *Node { - data := &JSDocUnknownTag{} + data := f.jsdocUnknownTagPool.New() data.TagName = tagName data.Comment = comment return f.newNode(KindJSDocTag, data) @@ -9275,7 +9295,7 @@ type ( ) func (f *NodeFactory) newJSDocParameterOrPropertyTag(kind Kind, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node { - data := &JSDocParameterOrPropertyTag{} + data := f.jsdocParameterOrPropertyTagPool.New() data.TagName = tagName data.name = name data.IsBracketed = isBracketed @@ -9523,7 +9543,7 @@ type JSDocDeprecatedTag struct { } func (f *NodeFactory) NewJSDocDeprecatedTag(tagName *IdentifierNode, comment *NodeList) *Node { - data := &JSDocDeprecatedTag{} + data := f.jsdocDeprecatedTagPool.New() data.TagName = tagName data.Comment = comment return f.newNode(KindJSDocDeprecatedTag, data) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index ca4dd45f4a..08d4c098d5 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -22,7 +22,6 @@ import ( "github.com/microsoft/typescript-go/internal/jsnum" "github.com/microsoft/typescript-go/internal/module" "github.com/microsoft/typescript-go/internal/modulespecifiers" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/stringutil" "github.com/microsoft/typescript-go/internal/tsoptions" @@ -849,13 +848,13 @@ type Checker struct { markNodeAssignments func(*ast.Node) bool emitResolver *emitResolver emitResolverOnce sync.Once - diagnosticConstructionContext *printer.EmitContext - nodeBuilder *NodeBuilder _jsxNamespace string _jsxFactoryEntity *ast.Node skipDirectInferenceNodes collections.Set[*ast.Node] ctx context.Context packagesMap map[string]bool + activeMappers []*TypeMapper + activeTypeMappersCaches []map[string]*Type } func NewChecker(program Program) *Checker { @@ -1068,8 +1067,6 @@ func NewChecker(program Program) *Checker { c.getGlobalClassAccessorDecoratorTargetType = c.getGlobalTypeResolver("ClassAccessorDecoratorTarget", 2 /*arity*/, true /*reportErrors*/) c.getGlobalClassAccessorDecoratorResultType = c.getGlobalTypeResolver("ClassAccessorDecoratorResult", 2 /*arity*/, true /*reportErrors*/) c.getGlobalClassFieldDecoratorContextType = c.getGlobalTypeResolver("ClassFieldDecoratorContext", 2 /*arity*/, true /*reportErrors*/) - c.diagnosticConstructionContext = printer.NewEmitContext() - c.nodeBuilder = NewNodeBuilder(c, c.diagnosticConstructionContext) c.initializeClosures() c.initializeIterationResolvers() c.initializeChecker() @@ -17879,6 +17876,7 @@ func (c *Checker) pushTypeResolution(target TypeSystemEntity, propertyName TypeS func (c *Checker) popTypeResolution() bool { lastIndex := len(c.typeResolutions) - 1 result := c.typeResolutions[lastIndex].result + c.typeResolutions[lastIndex] = TypeResolution{} // Clear the last entry to avoid memory leaks c.typeResolutions = c.typeResolutions[:lastIndex] return result } @@ -21133,6 +21131,9 @@ func (c *Checker) getDefaultOrUnknownFromTypeParameter(t *Type) *Type { } func (c *Checker) getNamedMembers(members ast.SymbolTable) []*ast.Symbol { + if len(members) == 0 { + return nil + } result := make([]*ast.Symbol, 0, len(members)) for id, symbol := range members { if c.isNamedMember(symbol, id) { @@ -21174,14 +21175,66 @@ func (c *Checker) instantiateTypeWithAlias(t *Type, m *TypeMapper, alias *TypeAl c.error(c.currentNode, diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite) return c.errorType } + index := c.findActiveMapper(m) + if index == -1 { + c.pushActiveMapper(m) + } + var b KeyBuilder + b.WriteType(t) + b.WriteAlias(alias) + key := b.String() + cache := c.activeTypeMappersCaches[core.IfElse(index != -1, index, len(c.activeTypeMappersCaches)-1)] + if cachedType, ok := cache[key]; ok { + return cachedType + } c.TotalInstantiationCount++ c.instantiationCount++ c.instantiationDepth++ result := c.instantiateTypeWorker(t, m, alias) + if index == -1 { + c.popActiveMapper() + } else { + cache[key] = result + } c.instantiationDepth-- return result } +func (c *Checker) pushActiveMapper(mapper *TypeMapper) { + c.activeMappers = append(c.activeMappers, mapper) + + lastIndex := len(c.activeTypeMappersCaches) + if cap(c.activeTypeMappersCaches) > lastIndex { + // The cap may contain an empty map from popActiveMapper; reuse it. + c.activeTypeMappersCaches = c.activeTypeMappersCaches[:lastIndex+1] + if c.activeTypeMappersCaches[lastIndex] == nil { + c.activeTypeMappersCaches[lastIndex] = make(map[string]*Type, 1) + } + } else { + c.activeTypeMappersCaches = append(c.activeTypeMappersCaches, make(map[string]*Type, 1)) + } +} + +func (c *Checker) popActiveMapper() { + c.activeMappers[len(c.activeMappers)-1] = nil + c.activeMappers = c.activeMappers[:len(c.activeMappers)-1] + + // Clear the map, but leave it in the list for later reuse. + lastIndex := len(c.activeTypeMappersCaches) - 1 + clear(c.activeTypeMappersCaches[lastIndex]) + c.activeTypeMappersCaches = c.activeTypeMappersCaches[:lastIndex] +} + +func (c *Checker) findActiveMapper(mapper *TypeMapper) int { + return core.FindLastIndex(c.activeMappers, func(m *TypeMapper) bool { return m == mapper }) +} + +func (c *Checker) clearActiveMapperCaches() { + for _, cache := range c.activeTypeMappersCaches { + clear(cache) + } +} + // Return true if the given type could possibly reference a type parameter for which // we perform type inference (i.e. a type parameter of a generic function). We cache // results for union and intersection types for performance reasons. @@ -29351,7 +29404,9 @@ func (c *Checker) pushContextualType(node *ast.Node, t *Type, isCache bool) { } func (c *Checker) popContextualType() { - c.contextualInfos = c.contextualInfos[:len(c.contextualInfos)-1] + lastIndex := len(c.contextualInfos) - 1 + c.contextualInfos[lastIndex] = ContextualInfo{} + c.contextualInfos = c.contextualInfos[:lastIndex] } func (c *Checker) findContextualNode(node *ast.Node, includeCaches bool) int { @@ -29421,7 +29476,9 @@ func (c *Checker) pushInferenceContext(node *ast.Node, context *InferenceContext } func (c *Checker) popInferenceContext() { - c.inferenceContextInfos = c.inferenceContextInfos[:len(c.inferenceContextInfos)-1] + lastIndex := len(c.inferenceContextInfos) - 1 + c.inferenceContextInfos[lastIndex] = InferenceContextInfo{} + c.inferenceContextInfos = c.inferenceContextInfos[:lastIndex] } func (c *Checker) getInferenceContext(node *ast.Node) *InferenceContext { diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go index 161be261eb..3034d35b5d 100644 --- a/internal/checker/checker_test.go +++ b/internal/checker/checker_test.go @@ -36,7 +36,7 @@ foo.bar;` fs = bundled.WrapFS(fs) cd := "/" - host := compiler.NewCompilerHost(nil, cd, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(cd, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil) assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line") @@ -70,7 +70,7 @@ func TestCheckSrcCompiler(t *testing.T) { rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler") - host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil) assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line") p := compiler.NewProgram(compiler.ProgramOptions{ @@ -87,7 +87,7 @@ func BenchmarkNewChecker(b *testing.B) { rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler") - host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil) assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line") p := compiler.NewProgram(compiler.ProgramOptions{ diff --git a/internal/checker/inference.go b/internal/checker/inference.go index 9ddbffd151..2d8db851cc 100644 --- a/internal/checker/inference.go +++ b/internal/checker/inference.go @@ -1329,6 +1329,7 @@ func (c *Checker) getInferredType(n *InferenceContext, index int) *Type { } inference.inferredType = inferredType } + c.clearActiveMapperCaches() } return inference.inferredType } diff --git a/internal/checker/nodebuilder.go b/internal/checker/nodebuilder.go index 0a8570ea8f..b6be4efda6 100644 --- a/internal/checker/nodebuilder.go +++ b/internal/checker/nodebuilder.go @@ -170,6 +170,6 @@ func NewNodeBuilder(ch *Checker, e *printer.EmitContext) *NodeBuilder { return &NodeBuilder{impl: impl, ctxStack: make([]*NodeBuilderContext, 0, 1), host: ch.program} } -func (c *Checker) GetDiagnosticNodeBuilder() *NodeBuilder { - return c.nodeBuilder +func (c *Checker) getNodeBuilder() *NodeBuilder { + return NewNodeBuilder(c, printer.NewEmitContext()) } diff --git a/internal/checker/printer.go b/internal/checker/printer.go index 4b668e2c16..fe0affceda 100644 --- a/internal/checker/printer.go +++ b/internal/checker/printer.go @@ -182,7 +182,8 @@ func (c *Checker) typeToStringEx(t *Type, enclosingDeclaration *ast.Node, flags if noTruncation { combinedFlags = combinedFlags | nodebuilder.FlagsNoTruncation } - typeNode := c.nodeBuilder.TypeToTypeNode(t, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) + nodeBuilder := c.getNodeBuilder() + typeNode := nodeBuilder.TypeToTypeNode(t, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) if typeNode == nil { panic("should always get typenode") } @@ -190,9 +191,9 @@ func (c *Checker) typeToStringEx(t *Type, enclosingDeclaration *ast.Node, flags // Otherwise, we always strip comments out. var printer *printer.Printer if t == c.unresolvedType { - printer = createPrinterWithDefaults(c.diagnosticConstructionContext) + printer = createPrinterWithDefaults(nodeBuilder.EmitContext()) } else { - printer = createPrinterWithRemoveComments(c.diagnosticConstructionContext) + printer = createPrinterWithRemoveComments(nodeBuilder.EmitContext()) } var sourceFile *ast.SourceFile if enclosingDeclaration != nil { @@ -245,22 +246,23 @@ func (c *Checker) symbolToStringEx(symbol *ast.Symbol, enclosingDeclaration *ast internalNodeFlags |= nodebuilder.InternalFlagsWriteComputedProps } + nodeBuilder := c.getNodeBuilder() var sourceFile *ast.SourceFile if enclosingDeclaration != nil { sourceFile = ast.GetSourceFileOfNode(enclosingDeclaration) } var printer_ *printer.Printer if enclosingDeclaration != nil && enclosingDeclaration.Kind == ast.KindSourceFile { - printer_ = createPrinterWithRemoveCommentsNeverAsciiEscape(c.diagnosticConstructionContext) + printer_ = createPrinterWithRemoveCommentsNeverAsciiEscape(nodeBuilder.EmitContext()) } else { - printer_ = createPrinterWithRemoveComments(c.diagnosticConstructionContext) + printer_ = createPrinterWithRemoveComments(nodeBuilder.EmitContext()) } var builder func(symbol *ast.Symbol, meaning ast.SymbolFlags, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node if flags&SymbolFormatFlagsAllowAnyNodeKind != 0 { - builder = c.nodeBuilder.SymbolToNode + builder = nodeBuilder.SymbolToNode } else { - builder = c.nodeBuilder.SymbolToEntityName + builder = nodeBuilder.SymbolToEntityName } entity := builder(symbol, meaning, enclosingDeclaration, nodeFlags, internalNodeFlags, nil) // TODO: GH#18217 printer_.Write(entity /*sourceFile*/, sourceFile, getTrailingSemicolonDeferringWriter(writer), nil) // TODO: GH#18217 @@ -294,9 +296,10 @@ func (c *Checker) signatureToStringEx(signature *Signature, enclosingDeclaration writer, putWriter := printer.GetSingleLineStringWriter() defer putWriter() + nodeBuilder := c.getNodeBuilder() combinedFlags := toNodeBuilderFlags(flags) | nodebuilder.FlagsIgnoreErrors | nodebuilder.FlagsWriteTypeParametersInQualifiedName - sig := c.nodeBuilder.SignatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) - printer_ := createPrinterWithRemoveCommentsOmitTrailingSemicolon(c.diagnosticConstructionContext) + sig := nodeBuilder.SignatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) + printer_ := createPrinterWithRemoveCommentsOmitTrailingSemicolon(nodeBuilder.EmitContext()) var sourceFile *ast.SourceFile if enclosingDeclaration != nil { sourceFile = ast.GetSourceFileOfNode(enclosingDeclaration) @@ -312,9 +315,10 @@ func (c *Checker) typePredicateToString(typePredicate *TypePredicate) string { func (c *Checker) typePredicateToStringEx(typePredicate *TypePredicate, enclosingDeclaration *ast.Node, flags TypeFormatFlags) string { writer, putWriter := printer.GetSingleLineStringWriter() defer putWriter() + nodeBuilder := c.getNodeBuilder() combinedFlags := toNodeBuilderFlags(flags) | nodebuilder.FlagsIgnoreErrors | nodebuilder.FlagsWriteTypeParametersInQualifiedName - predicate := c.nodeBuilder.TypePredicateToTypePredicateNode(typePredicate, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) // TODO: GH#18217 - printer_ := createPrinterWithRemoveComments(c.diagnosticConstructionContext) + predicate := nodeBuilder.TypePredicateToTypePredicateNode(typePredicate, enclosingDeclaration, combinedFlags, nodebuilder.InternalFlagsNone, nil) // TODO: GH#18217 + printer_ := createPrinterWithRemoveComments(nodeBuilder.EmitContext()) var sourceFile *ast.SourceFile if enclosingDeclaration != nil { sourceFile = ast.GetSourceFileOfNode(enclosingDeclaration) diff --git a/internal/checker/types.go b/internal/checker/types.go index 02b4a3c233..9f97173880 100644 --- a/internal/checker/types.go +++ b/internal/checker/types.go @@ -297,34 +297,6 @@ const ( AccessFlagsPersistent = AccessFlagsIncludeUndefined ) -type AssignmentDeclarationKind = int32 - -const ( - AssignmentDeclarationKindNone = AssignmentDeclarationKind(iota) - /// exports.name = expr - /// module.exports.name = expr - AssignmentDeclarationKindExportsProperty - /// module.exports = expr - AssignmentDeclarationKindModuleExports - /// className.prototype.name = expr - AssignmentDeclarationKindPrototypeProperty - /// this.name = expr - AssignmentDeclarationKindThisProperty - // F.name = expr - AssignmentDeclarationKindProperty - // F.prototype = { ... } - AssignmentDeclarationKindPrototype - // Object.defineProperty(x, 'name', { value: any, writable?: boolean (false by default) }); - // Object.defineProperty(x, 'name', { get: Function, set: Function }); - // Object.defineProperty(x, 'name', { get: Function }); - // Object.defineProperty(x, 'name', { set: Function }); - AssignmentDeclarationKindObjectDefinePropertyValue - // Object.defineProperty(exports || module.exports, 'name', ...); - AssignmentDeclarationKindObjectDefinePropertyExports - // Object.defineProperty(Foo.prototype, 'name', ...); - AssignmentDeclarationKindObjectDefinePrototypeProperty -) - type NodeCheckFlags uint32 const ( 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/compiler/fileloader.go b/internal/compiler/fileloader.go index 708307c455..cc1d113759 100644 --- a/internal/compiler/fileloader.go +++ b/internal/compiler/fileloader.go @@ -54,6 +54,7 @@ type processedFiles struct { // List of present unsupported extensions unsupportedExtensions []string sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path] + fileLoadDiagnostics *ast.DiagnosticsCollection } type jsxRuntimeImportSpecifier struct { @@ -93,7 +94,7 @@ func processAllProgramFiles( loader.resolver = module.NewResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName) var libs []string - if compilerOptions.NoLib.IsFalseOrUnknown() { + if len(rootFiles) > 0 && compilerOptions.NoLib.IsFalseOrUnknown() { if compilerOptions.Lib == nil { name := tsoptions.GetDefaultLibFileName(compilerOptions) libs = append(libs, loader.pathForLibFile(name)) @@ -109,7 +110,10 @@ func processAllProgramFiles( loader.addRootTasks(rootFiles, false) loader.addRootTasks(libs, true) - loader.addAutomaticTypeDirectiveTasks() + + if len(rootFiles) > 0 { + loader.addAutomaticTypeDirectiveTasks() + } loader.parseTasks.runAndWait(&loader, loader.rootTasks) // Clear out loader and host to ensure its not used post program creation @@ -132,6 +136,7 @@ func processAllProgramFiles( var unsupportedExtensions []string var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path] var libFileSet collections.Set[tspath.Path] + fileLoadDiagnostics := &ast.DiagnosticsCollection{} loader.parseTasks.collect(&loader, loader.rootTasks, func(task *parseTask, _ []tspath.Path) { if task.isRedirected { @@ -159,6 +164,7 @@ func processAllProgramFiles( resolvedModules[path] = task.resolutionsInFile typeResolutionsInFile[path] = task.typeResolutionsInFile sourceFileMetaDatas[path] = task.metadata + if task.jsxRuntimeImportSpecifier != nil { if jsxRuntimeImportSpecifiers == nil { jsxRuntimeImportSpecifiers = make(map[tspath.Path]*jsxRuntimeImportSpecifier, totalFileCount) @@ -183,8 +189,28 @@ func processAllProgramFiles( allFiles := append(libFiles, files...) + for _, resolutions := range resolvedModules { + for _, resolvedModule := range resolutions { + for _, diag := range resolvedModule.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } + } + for _, typeResolutions := range typeResolutionsInFile { + for _, resolvedTypeRef := range typeResolutions { + for _, diag := range resolvedTypeRef.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } + } + loader.pathForLibFileResolutions.Range(func(key tspath.Path, value module.ModeAwareCache[*module.ResolvedModule]) bool { resolvedModules[key] = value + for _, resolvedModule := range value { + for _, diag := range resolvedModule.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } return true }) @@ -201,6 +227,7 @@ func processAllProgramFiles( unsupportedExtensions: unsupportedExtensions, sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules, libFiles: libFileSet, + fileLoadDiagnostics: fileLoadDiagnostics, } } @@ -372,6 +399,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) { resolutionMode := getModeForTypeReferenceDirectiveInFile(ref, file, meta, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect)) resolved := p.resolver.ResolveTypeReferenceDirective(ref.FileName, file.FileName(), resolutionMode, redirect) typeResolutionsInFile[module.ModeAwareCacheKey{Name: ref.FileName, Mode: resolutionMode}] = resolved + if resolved.IsResolved() { t.addSubTask(resolvedRef{ fileName: resolved.ResolvedFileName, diff --git a/internal/compiler/host.go b/internal/compiler/host.go index 82c8c697a3..8c480e896a 100644 --- a/internal/compiler/host.go +++ b/internal/compiler/host.go @@ -2,7 +2,6 @@ package compiler import ( "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/collections" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/parser" "github.com/microsoft/typescript-go/internal/tsoptions" @@ -15,50 +14,36 @@ type CompilerHost interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string Trace(msg string) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine } -type FileInfo struct { - Name string - Size int64 -} - var _ CompilerHost = (*compilerHost)(nil) type compilerHost struct { - options *core.CompilerOptions - currentDirectory string - fs vfs.FS - defaultLibraryPath string - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry] + currentDirectory string + fs vfs.FS + defaultLibraryPath string } func NewCachedFSCompilerHost( - options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath string, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], ) CompilerHost { - return NewCompilerHost(options, currentDirectory, cachedvfs.From(fs), defaultLibraryPath, extendedConfigCache) + return NewCompilerHost(currentDirectory, cachedvfs.From(fs), defaultLibraryPath) } func NewCompilerHost( - options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath string, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], ) CompilerHost { return &compilerHost{ - options: options, - currentDirectory: currentDirectory, - fs: fs, - defaultLibraryPath: defaultLibraryPath, - extendedConfigCache: extendedConfigCache, + currentDirectory: currentDirectory, + fs: fs, + defaultLibraryPath: defaultLibraryPath, } } @@ -70,21 +55,10 @@ func (h *compilerHost) DefaultLibraryPath() string { return h.defaultLibraryPath } -func (h *compilerHost) SetOptions(options *core.CompilerOptions) { - h.options = options -} - func (h *compilerHost) GetCurrentDirectory() string { return h.currentDirectory } -func (h *compilerHost) NewLine() string { - if h.options == nil { - return "\n" - } - return h.options.NewLine.GetNewLineCharacter() -} - func (h *compilerHost) Trace(msg string) { //!!! TODO: implement } diff --git a/internal/compiler/parsetask.go b/internal/compiler/parsetask.go index ebb6fdcce3..9d7045bfc4 100644 --- a/internal/compiler/parsetask.go +++ b/internal/compiler/parsetask.go @@ -22,6 +22,7 @@ type parseTask struct { metadata ast.SourceFileMetaData resolutionsInFile module.ModeAwareCache[*module.ResolvedModule] typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective] + resolutionDiagnostics []*ast.Diagnostic importHelpersImportSpecifier *ast.Node jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier increaseDepth bool diff --git a/internal/compiler/program.go b/internal/compiler/program.go index fa2ac6e908..41cc605594 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -330,7 +330,16 @@ func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast. return p.getDiagnosticsHelper(ctx, sourceFile, true /*ensureBound*/, true /*ensureChecked*/, p.getSuggestionDiagnosticsForFile) } +func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic { + // !!! + return SortAndDeduplicateDiagnostics(p.fileLoadDiagnostics.GetDiagnostics()) +} + func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic { + if len(p.files) == 0 { + return nil + } + var globalDiagnostics []*ast.Diagnostic checkers, done := p.checkerPool.GetAllCheckers(ctx) defer done() diff --git a/internal/compiler/program_test.go b/internal/compiler/program_test.go index 0043848cef..c723b234ab 100644 --- a/internal/compiler/program_test.go +++ b/internal/compiler/program_test.go @@ -240,7 +240,7 @@ func TestProgram(t *testing.T) { CompilerOptions: &opts, }, }, - Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil), + Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()), }) actualFiles := []string{} @@ -277,7 +277,7 @@ func BenchmarkNewProgram(b *testing.B) { CompilerOptions: &opts, }, }, - Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil), + Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()), } for b.Loop() { @@ -294,7 +294,7 @@ func BenchmarkNewProgram(b *testing.B) { fs := osvfs.FS() fs = bundled.WrapFS(fs) - host := NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, host, nil) assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line") diff --git a/internal/execute/outputs.go b/internal/execute/outputs.go index 9a1f73d4ca..3e2e9a7ddd 100644 --- a/internal/execute/outputs.go +++ b/internal/execute/outputs.go @@ -98,7 +98,7 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm } func printVersion(sys System) { - fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version())+sys.NewLine()) + fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Format(core.Version())) sys.EndWrite() } @@ -144,7 +144,7 @@ func getHeader(sys System, message string) []string { // header.push("".padStart(leftAlign) + tsIconSecondLine + sys.newLine); // } // else { - header = append(header, message+sys.NewLine(), sys.NewLine()) + header = append(header, message+"\n", "\n") // } return header } @@ -156,15 +156,15 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) { for _, example := range examples { // !!! colors // output.push(" " + colors.blue(example) + sys.newLine); - output = append(output, " ", example, sys.NewLine()) + output = append(output, " ", example, "\n") } - output = append(output, " ", desc.Format(), sys.NewLine(), sys.NewLine()) + output = append(output, " ", desc.Format(), "\n", "\n") } msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version()) output = append(output, getHeader(sys, msg)...) - output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, sys.NewLine(), sys.NewLine()) + output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, "\n", "\n") example([]string{"tsc"}, diagnostics.Compiles_the_current_project_tsconfig_json_in_the_working_directory) example([]string{"tsc app.ts util.ts"}, diagnostics.Ignoring_tsconfig_json_compiles_the_specified_files_with_default_compiler_options) @@ -206,15 +206,15 @@ func generateSectionOptionsOutput( afterOptionsDescription *string, ) (output []string) { // !!! color - output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, sys.NewLine(), sys.NewLine()) + output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, "\n", "\n") if beforeOptionsDescription != nil { - output = append(output, *beforeOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *beforeOptionsDescription, "\n", "\n") } if !subCategory { output = append(output, generateGroupOptionOutput(sys, options)...) if afterOptionsDescription != nil { - output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *afterOptionsDescription, "\n", "\n") } return output } @@ -227,11 +227,11 @@ func generateSectionOptionsOutput( categoryMap[curCategory] = append(categoryMap[curCategory], option) } for key, value := range categoryMap { - output = append(output, "### ", key, sys.NewLine(), sys.NewLine()) + output = append(output, "### ", key, "\n", "\n") output = append(output, generateGroupOptionOutput(sys, value)...) } if afterOptionsDescription != nil { - output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *afterOptionsDescription, "\n", "\n") } return output @@ -258,8 +258,8 @@ func generateGroupOptionOutput(sys System, optionsList []*tsoptions.CommandLineO } // make sure always a blank line in the end. - if len(lines) < 2 || lines[len(lines)-2] != sys.NewLine() { - lines = append(lines, sys.NewLine()) + if len(lines) < 2 || lines[len(lines)-2] != "\n" { + lines = append(lines, "\n") } return lines @@ -312,25 +312,25 @@ func generateOptionOutput( // !!! } // !!! text.push(sys.newLine); } else { - text = append(text /* !!! colors.blue(name) */, name, sys.NewLine()) + text = append(text /* !!! colors.blue(name) */, name, "\n") if option.Description != nil { text = append(text, option.Description.Format()) } - text = append(text, sys.NewLine()) + text = append(text, "\n") if showAdditionalInfoOutput(valueCandidates, option) { if valueCandidates != nil { text = append(text, valueCandidates.valueType, " ", valueCandidates.possibleValues) } if defaultValueDescription != "" { if valueCandidates != nil { - text = append(text, sys.NewLine()) + text = append(text, "\n") } text = append(text, diagnostics.X_default_Colon.Format(), " ", defaultValueDescription) } - text = append(text, sys.NewLine()) + text = append(text, "\n") } - text = append(text, sys.NewLine()) + text = append(text, "\n") } return text diff --git a/internal/execute/system.go b/internal/execute/system.go index 3861a04392..a31101dd3c 100644 --- a/internal/execute/system.go +++ b/internal/execute/system.go @@ -13,7 +13,6 @@ type System interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string // #241 eventually we want to use "\n" Now() time.Time SinceStart() time.Duration diff --git a/internal/execute/testsys_test.go b/internal/execute/testsys_test.go index 92eda1f4ad..789dcec088 100644 --- a/internal/execute/testsys_test.go +++ b/internal/execute/testsys_test.go @@ -72,10 +72,6 @@ func (s *testSys) GetCurrentDirectory() string { return s.cwd } -func (s *testSys) NewLine() string { - return "\n" -} - func (s *testSys) Writer() io.Writer { return s.currentWrite } diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index f680ff880a..615247e19c 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -46,7 +46,7 @@ func CommandLine(sys System, cb cbType, commandLineArgs []string) ExitStatus { // !!! build mode switch strings.ToLower(commandLineArgs[0]) { case "-b", "--b", "-build", "--build": - fmt.Fprint(sys.Writer(), "Build mode is currently unsupported."+sys.NewLine()) + fmt.Fprintln(sys.Writer(), "Build mode is currently unsupported.") sys.EndWrite() return ExitStatusNotImplemented // case "-f": @@ -63,12 +63,12 @@ func CommandLine(sys System, cb cbType, commandLineArgs []string) ExitStatus { } func fmtMain(sys System, input, output string) ExitStatus { - ctx := format.WithFormatCodeSettings(context.Background(), format.GetDefaultFormatCodeSettings(sys.NewLine()), sys.NewLine()) + ctx := format.WithFormatCodeSettings(context.Background(), format.GetDefaultFormatCodeSettings("\n"), "\n") input = string(tspath.ToPath(input, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) output = string(tspath.ToPath(output, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) fileContent, ok := sys.FS().ReadFile(input) if !ok { - fmt.Fprint(sys.Writer(), "File not found: "+input+sys.NewLine()) + fmt.Fprintln(sys.Writer(), "File not found:", input) return ExitStatusNotImplemented } text := fileContent @@ -82,7 +82,7 @@ func fmtMain(sys System, input, output string) ExitStatus { newText := applyBulkEdits(text, edits) if err := sys.FS().WriteFile(output, newText, false); err != nil { - fmt.Fprint(sys.Writer(), err.Error()+sys.NewLine()) + fmt.Fprintln(sys.Writer(), err.Error()) return ExitStatusNotImplemented } return ExitStatusSuccess @@ -188,7 +188,6 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars cb, configParseResult, reportDiagnostic, - &extendedConfigCache, configTime, ), nil } else { @@ -208,7 +207,6 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars cb, commandLine, reportDiagnostic, - nil, 0, /*configTime*/ ), nil } @@ -232,10 +230,9 @@ func performCompilation( cb cbType, config *tsoptions.ParsedCommandLine, reportDiagnostic diagnosticReporter, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], configTime time.Duration, ) ExitStatus { - host := compiler.NewCachedFSCompilerHost(config.CompilerOptions(), sys.GetCurrentDirectory(), sys.FS(), sys.DefaultLibraryPath(), extendedConfigCache) + host := compiler.NewCachedFSCompilerHost(sys.GetCurrentDirectory(), sys.FS(), sys.DefaultLibraryPath()) // todo: cache, statistics, tracing parseStart := sys.Now() program := compiler.NewProgram(compiler.ProgramOptions{ @@ -296,6 +293,7 @@ func emitFilesAndReportErrors(sys System, program *compiler.Program, reportDiagn configFileParsingDiagnosticsLength := len(allDiagnostics) allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, nil)...) + allDiagnostics = append(allDiagnostics, program.GetProgramDiagnostics()...) if len(allDiagnostics) == configFileParsingDiagnosticsLength { // Options diagnostics include global diagnostics (even though we collect them separately), @@ -373,7 +371,7 @@ func listFiles(sys System, program *compiler.Program) { // !!! explainFiles if options.ListFiles.IsTrue() || options.ListFilesOnly.IsTrue() { for _, file := range program.GetSourceFiles() { - fmt.Fprintf(sys.Writer(), "%s%s", file.FileName(), sys.NewLine()) + fmt.Fprintln(sys.Writer(), file.FileName()) } } } diff --git a/internal/execute/watch.go b/internal/execute/watch.go index 6d587951d1..e1b2b9dbb3 100644 --- a/internal/execute/watch.go +++ b/internal/execute/watch.go @@ -24,7 +24,7 @@ func start(w *watcher) ExitStatus { func (w *watcher) initialize() { // if this function is updated, make sure to update `StartForTest` in export_test.go as needed if w.configFileName == "" { - w.host = compiler.NewCompilerHost(w.options.CompilerOptions(), w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath(), nil) + w.host = compiler.NewCompilerHost(w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath()) } } @@ -42,12 +42,12 @@ func (w *watcher) doCycle() { JSDocParsingMode: ast.JSDocParsingModeParseForTypeErrors, }) if w.hasBeenModified(w.program) { - fmt.Fprint(w.sys.Writer(), "build starting at ", w.sys.Now(), w.sys.NewLine()) + fmt.Fprintln(w.sys.Writer(), "build starting at", w.sys.Now()) timeStart := w.sys.Now() w.compileAndEmit() - fmt.Fprint(w.sys.Writer(), "build finished in ", w.sys.Now().Sub(timeStart), w.sys.NewLine()) + fmt.Fprintln(w.sys.Writer(), "build finished in", w.sys.Now().Sub(timeStart)) } else { // print something??? - // fmt.Fprint(w.sys.Writer(), "no changes detected at ", w.sys.Now(), w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "no changes detected at", w.sys.Now()) } } diff --git a/internal/execute/watcher.go b/internal/execute/watcher.go index 5697c7525d..716a262460 100644 --- a/internal/execute/watcher.go +++ b/internal/execute/watcher.go @@ -56,11 +56,11 @@ func (w *watcher) hasErrorsInTsConfig() bool { } // CompilerOptions contain fields which should not be compared; clone to get a copy without those set. if !reflect.DeepEqual(w.options.CompilerOptions().Clone(), configParseResult.CompilerOptions().Clone()) { - // fmt.Fprint(w.sys.Writer(), "build triggered due to config change", w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "build triggered due to config change") w.configModified = true } w.options = configParseResult - w.host = compiler.NewCompilerHost(w.options.CompilerOptions(), w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath(), &extendedConfigCache) + w.host = compiler.NewCompilerHost(w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath()) } return false } @@ -80,7 +80,7 @@ func (w *watcher) hasBeenModified(program *compiler.Program) bool { currState[fileName] = s.ModTime() if !filesModified { if currState[fileName] != w.prevModified[fileName] { - // fmt.Fprint(w.sys.Writer(), "build triggered from ", fileName, ": ", w.prevModified[fileName], " -> ", currState[fileName], w.sys.NewLine()) + // fmt.Fprint(w.sys.Writer(), "build triggered from ", fileName, ": ", w.prevModified[fileName], " -> ", currState[fileName], "\n") filesModified = true } // catch cases where no files are modified, but some were deleted @@ -88,7 +88,7 @@ func (w *watcher) hasBeenModified(program *compiler.Program) bool { } } if !filesModified && len(w.prevModified) > 0 { - // fmt.Fprint(w.sys.Writer(), "build triggered due to deleted file", w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "build triggered due to deleted file") filesModified = true } w.prevModified = currState diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index e099c59f0e..1ad7ea20d8 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -2,6 +2,7 @@ import * as cp from "child_process"; import * as fs from "fs"; import * as path from "path"; import * as ts from "typescript"; +import * as url from "url"; import which from "which"; const stradaFourslashPath = path.resolve(import.meta.dirname, "../", "../", "../", "_submodules", "TypeScript", "tests", "cases", "fourslash"); @@ -9,15 +10,18 @@ const stradaFourslashPath = path.resolve(import.meta.dirname, "../", "../", "../ let inputFileSet: Set | undefined; const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt"); -const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0); -const failingTests = new Set(failingTestsList); const helperFilePath = path.join(import.meta.dirname, "../", "tests", "util_test.go"); const outputDir = path.join(import.meta.dirname, "../", "tests", "gen"); const unparsedFiles: string[] = []; -function main() { +function getFailingTests(): Set { + const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0); + return new Set(failingTestsList); +} + +export function main() { const args = process.argv.slice(2); const inputFilesPath = args[0]; if (inputFilesPath) { @@ -28,18 +32,17 @@ function main() { inputFileSet = new Set(inputFiles); } - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); - } + fs.rmSync(outputDir, { recursive: true, force: true }); + fs.mkdirSync(outputDir, { recursive: true }); generateHelperFile(); - parseTypeScriptFiles(stradaFourslashPath); + parseTypeScriptFiles(getFailingTests(), stradaFourslashPath); console.log(unparsedFiles.join("\n")); const gofmt = which.sync("go"); cp.execFileSync(gofmt, ["tool", "mvdan.cc/gofumpt", "-lang=go1.24", "-w", outputDir]); } -function parseTypeScriptFiles(folder: string): void { +function parseTypeScriptFiles(failingTests: Set, folder: string): void { const files = fs.readdirSync(folder); files.forEach(file => { @@ -50,13 +53,13 @@ function parseTypeScriptFiles(folder: string): void { } if (stat.isDirectory()) { - parseTypeScriptFiles(filePath); + parseTypeScriptFiles(failingTests, filePath); } else if (file.endsWith(".ts")) { const content = fs.readFileSync(filePath, "utf-8"); const test = parseFileContent(file, content); if (test) { - const testContent = generateGoTest(test); + const testContent = generateGoTest(failingTests, test); const testPath = path.join(outputDir, `${test.name}_test.go`); fs.writeFileSync(testPath, testContent, "utf-8"); } @@ -69,7 +72,7 @@ function parseFileContent(filename: string, content: string): GoTest | undefined const sourceFile = ts.createSourceFile("temp.ts", content, ts.ScriptTarget.Latest, true /*setParentNodes*/); const statements = sourceFile.statements; const goTest: GoTest = { - name: filename.replace(".ts", ""), + name: filename.replace(".ts", "").replace(".", ""), content: getTestInput(content), commands: [], }; @@ -138,13 +141,20 @@ 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") { - return parseGoToMarkerArgs(callExpression.arguments); + // `goTo....` + if (namespace.text === "goTo") { + return parseGoToArgs(callExpression.arguments, func.text); } // `edit....` if (namespace.text === "edit") { @@ -208,20 +218,83 @@ function getGoStringLiteral(text: string): string { return `${JSON.stringify(text)}`; } -function parseGoToMarkerArgs(args: readonly ts.Expression[]): GoToMarkerCmd[] | undefined { - if (args.length !== 1) { - console.error(`Expected exactly one argument in goTo.marker, got ${args.length}`); - return undefined; - } - const arg = args[0]; - if (!ts.isStringLiteral(arg)) { - console.error(`Unrecognized argument in goTo.marker: ${arg.getText()}`); - return undefined; +function parseGoToArgs(args: readonly ts.Expression[], funcName: string): GoToCmd[] | undefined { + switch (funcName) { + case "marker": + const arg = args[0]; + if (arg === undefined) { + return [{ + kind: "goTo", + funcName: "marker", + args: [`""`], + }]; + } + if (!ts.isStringLiteral(arg)) { + console.error(`Unrecognized argument in goTo.marker: ${arg.getText()}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "marker", + args: [getGoStringLiteral(arg.text)], + }]; + case "file": + if (args.length !== 1) { + console.error(`Expected a single argument in goTo.file, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + if (ts.isStringLiteral(args[0])) { + return [{ + kind: "goTo", + funcName: "file", + args: [getGoStringLiteral(args[0].text)], + }]; + } + else if (ts.isNumericLiteral(args[0])) { + return [{ + kind: "goTo", + funcName: "fileNumber", + args: [args[0].text], + }]; + } + console.error(`Expected string or number literal argument in goTo.file, got ${args[0].getText()}`); + return undefined; + case "position": + if (args.length !== 1 || !ts.isNumericLiteral(args[0])) { + console.error(`Expected a single numeric literal argument in goTo.position, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "position", + args: [`${args[0].text}`], + }]; + case "eof": + return [{ + kind: "goTo", + funcName: "EOF", + args: [], + }]; + case "bof": + return [{ + kind: "goTo", + funcName: "BOF", + args: [], + }]; + case "select": + if (args.length !== 2 || !ts.isStringLiteral(args[0]) || !ts.isStringLiteral(args[1])) { + console.error(`Expected two string literal arguments in goTo.select, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "select", + args: [getGoStringLiteral(args[0].text), getGoStringLiteral(args[1].text)], + }]; + default: + console.error(`Unrecognized goTo function: ${funcName}`); + return undefined; } - return [{ - kind: "goToMarker", - marker: getGoStringLiteral(arg.text), - }]; } function parseVerifyCompletionsArgs(args: readonly ts.Expression[]): VerifyCompletionsCmd[] | undefined { @@ -304,6 +377,7 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un break; case "exact": case "includes": + case "unsorted": if (init.getText() === "undefined") { return { kind: "verifyCompletions", @@ -385,9 +459,12 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un if (propName === "includes") { (goArgs ??= {}).includes = expected; } - else { + else if (propName === "exact") { (goArgs ??= {}).exact = expected; } + else { + (goArgs ??= {}).unsorted = expected; + } break; case "excludes": let excludes = "[]string{"; @@ -536,6 +613,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()}`); @@ -659,11 +757,26 @@ interface VerifyCompletionsArgs { includes?: string; excludes?: string; exact?: string; + unsorted?: string; } -interface GoToMarkerCmd { - kind: "goToMarker"; - marker: string; +interface VerifyBaselineFindAllReferencesCmd { + kind: "verifyBaselineFindAllReferences"; + markers: string[]; + ranges?: boolean; +} + +interface VerifyBaselineFindAllReferencesCmd { + kind: "verifyBaselineFindAllReferences"; + markers: string[]; + ranges?: boolean; +} + +interface GoToCmd { + kind: "goTo"; + // !!! `selectRange` and `rangeStart` require parsing variables and `test.ranges()[n]` + funcName: "marker" | "file" | "fileNumber" | "EOF" | "BOF" | "position" | "select"; + args: string[]; } interface EditCmd { @@ -671,7 +784,7 @@ interface EditCmd { goStatement: string; } -type Cmd = VerifyCompletionsCmd | GoToMarkerCmd | EditCmd; +type Cmd = VerifyCompletionsCmd | VerifyBaselineFindAllReferencesCmd | GoToCmd | EditCmd; function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: VerifyCompletionsCmd): string { let expectedList = "nil"; @@ -680,6 +793,7 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve if (args.includes) expected.push(`Includes: ${args.includes},`); if (args.excludes) expected.push(`Excludes: ${args.excludes},`); if (args.exact) expected.push(`Exact: ${args.exact},`); + if (args.unsorted) expected.push(`Unsorted: ${args.unsorted},`); // !!! isIncomplete const commitCharacters = isNewIdentifierLocation ? "[]string{}" : "defaultCommitCharacters"; expectedList = `&fourslash.CompletionsExpectedList{ @@ -696,16 +810,26 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve return `f.VerifyCompletions(t, ${marker}, ${expectedList})`; } -function generateGoToMarker({ marker }: GoToMarkerCmd): string { - return `f.GoToMarker(t, ${marker})`; +function generateBaselineFindAllReferences({ markers, ranges }: VerifyBaselineFindAllReferencesCmd): string { + if (ranges || markers.length === 0) { + return `f.VerifyBaselineFindAllReferences(t)`; + } + return `f.VerifyBaselineFindAllReferences(t, ${markers.join(", ")})`; +} + +function generateGoToCommand({ funcName, args }: GoToCmd): string { + const funcNameCapitalized = funcName.charAt(0).toUpperCase() + funcName.slice(1); + return `f.GoTo${funcNameCapitalized}(t, ${args.join(", ")})`; } function generateCmd(cmd: Cmd): string { switch (cmd.kind) { case "verifyCompletions": return generateVerifyCompletions(cmd as VerifyCompletionsCmd); - case "goToMarker": - return generateGoToMarker(cmd as GoToMarkerCmd); + case "verifyBaselineFindAllReferences": + return generateBaselineFindAllReferences(cmd as VerifyBaselineFindAllReferencesCmd); + case "goTo": + return generateGoToCommand(cmd as GoToCmd); case "edit": return cmd.goStatement; default: @@ -719,7 +843,7 @@ interface GoTest { commands: Cmd[]; } -function generateGoTest(test: GoTest): string { +function generateGoTest(failingTests: Set, test: GoTest): string { const testName = test.name[0].toUpperCase() + test.name.substring(1); const content = test.content; const commands = test.commands.map(cmd => generateCmd(cmd)).join("\n"); @@ -755,4 +879,6 @@ function generateHelperFile() { fs.copyFileSync(helperFilePath, path.join(outputDir, "util_test.go")); } -main(); +if (url.fileURLToPath(import.meta.url) == process.argv[1]) { + main(); +} diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 58428835d0..6c6a2c6860 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -1,8 +1,6 @@ TestAutoImportsWithRootDirsAndRootedPath01 TestClosedCommentsInConstructor TestCodeCompletionEscaping -TestCompletionAfterNewline -TestCompletionAfterNewline2 TestCompletionCloneQuestionToken TestCompletionEntryForArgumentConstrainedToString TestCompletionEntryForArrayElementConstrainedToString @@ -44,6 +42,8 @@ TestCompletionForStringLiteral_quotePreference3 TestCompletionForStringLiteral_quotePreference4 TestCompletionForStringLiteral_quotePreference5 TestCompletionForStringLiteral_quotePreference6 +TestCompletionForStringLiteral_quotePreference7 +TestCompletionForStringLiteral_quotePreference8 TestCompletionImportMeta TestCompletionImportMetaWithGlobalDeclaration TestCompletionImportModuleSpecifierEndingDts @@ -62,10 +62,10 @@ TestCompletionListAndMemberListOnCommentedWhiteSpace TestCompletionListAtInvalidLocations TestCompletionListBuilderLocations_VariableDeclarations TestCompletionListCladule +TestCompletionListClassMembers TestCompletionListForExportEquals TestCompletionListForTransitivelyExportedMembers01 TestCompletionListForTransitivelyExportedMembers04 -TestCompletionListForUnicodeEscapeName TestCompletionListFunctionExpression TestCompletionListFunctionMembers TestCompletionListInArrowFunctionInUnclosedCallSite01 @@ -75,7 +75,6 @@ TestCompletionListInComments TestCompletionListInComments2 TestCompletionListInComments3 TestCompletionListInExtendsClause -TestCompletionListInFunctionDeclaration TestCompletionListInImportClause01 TestCompletionListInImportClause05 TestCompletionListInImportClause06 @@ -85,14 +84,16 @@ TestCompletionListInUnclosedCommaExpression01 TestCompletionListInUnclosedCommaExpression02 TestCompletionListInUnclosedFunction08 TestCompletionListInUnclosedFunction09 -TestCompletionListInUnclosedFunction10 -TestCompletionListInUnclosedFunction11 TestCompletionListInUnclosedTaggedTemplate01 TestCompletionListInUnclosedTaggedTemplate02 TestCompletionListInUnclosedTemplate01 TestCompletionListInUnclosedTemplate02 TestCompletionListInvalidMemberNames2 TestCompletionListInvalidMemberNames_withExistingIdentifier +TestCompletionListOnAliases2 +TestCompletionListPrivateNames +TestCompletionListPrivateNamesAccessors +TestCompletionListPrivateNamesMethods TestCompletionListStaticMembers TestCompletionListStaticProtectedMembers TestCompletionListStaticProtectedMembers2 @@ -108,9 +109,7 @@ TestCompletionWithConditionalOperatorMissingColon TestCompletionsAfterJSDoc TestCompletionsBeforeRestArg1 TestCompletionsECMAPrivateMemberTriggerCharacter -TestCompletionsImportDefaultExportCrash1 TestCompletionsImport_computedSymbolName -TestCompletionsImport_umdDefaultNoCrash2 TestCompletionsInRequire TestCompletionsInterfaceElement TestCompletionsJSDocImportTagAttributesEmptyModuleSpecifier1 @@ -128,7 +127,6 @@ TestCompletionsMergedDeclarations1 TestCompletionsNamespaceMergedWithClass TestCompletionsNamespaceName TestCompletionsNewTarget -TestCompletionsNonExistentImport TestCompletionsOptionalKindModifier TestCompletionsOptionalMethod TestCompletionsOverridingMethod1 @@ -156,6 +154,18 @@ TestCompletionsTriggerCharacter TestCompletionsUniqueSymbol1 TestCompletionsWithStringReplacementMode1 TestExportEqualCallableInterface +TestFindAllReferencesTripleSlash +TestFindAllRefs_importType_typeofImport +TestFindAllRefsCommonJsRequire +TestFindAllRefsCommonJsRequire2 +TestFindAllRefsCommonJsRequire3 +TestFindAllRefsExportEquals +TestFindAllRefsForDefaultExport03 +TestFindAllRefsJsDocImportTag +TestFindAllRefsModuleDotExports +TestFindAllRefsReExport_broken +TestFindAllReferencesUmdModuleAsGlobalConst +TestFindReferencesAfterEdit TestGetJavaScriptCompletions1 TestGetJavaScriptCompletions10 TestGetJavaScriptCompletions11 @@ -176,6 +186,7 @@ TestGetJavaScriptCompletions8 TestGetJavaScriptCompletions9 TestGetJavaScriptGlobalCompletions1 TestGetJavaScriptQuickInfo8 +TestGlobalThisCompletion TestImportCompletionsPackageJsonExportsSpecifierEndsInTs TestImportCompletionsPackageJsonExportsTrailingSlash1 TestImportCompletionsPackageJsonImportsConditions1 @@ -198,8 +209,11 @@ TestImportStatementCompletions4 TestImportStatementCompletions_noPatternAmbient TestImportStatementCompletions_pnpmTransitive TestImportTypeMemberCompletions +TestJavaScriptClass4 TestJavaScriptModules12 +TestJavaScriptModules13 TestJavaScriptModules14 +TestJavaScriptModules19 TestJavascriptModules20 TestJavascriptModules21 TestJavascriptModulesTypeImport @@ -207,6 +221,7 @@ TestJsDocFunctionSignatures3 TestJsDocGenerics1 TestJsdocExtendsTagCompletion TestJsdocImplementsTagCompletion +TestJsdocLink_findAllReferences1 TestJsdocOverloadTagCompletion TestJsdocParamTagSpecialKeywords TestJsdocParameterNameCompletion @@ -221,6 +236,9 @@ TestJsdocTypedefTag2 TestJsdocTypedefTagNamespace TestJsdocTypedefTagTypeExpressionCompletion TestJsxAriaLikeCompletions +TestJsxFindAllReferencesOnRuntimeImportWithPaths1 +TestLocalGetReferences +TestJsxQualifiedTagCompletion TestMemberListErrorRecovery TestMemberListInWithBlock TestMemberListOnConstructorType @@ -274,7 +292,11 @@ TestPathCompletionsTypesVersionsWildcard3 TestPathCompletionsTypesVersionsWildcard4 TestPathCompletionsTypesVersionsWildcard5 TestPathCompletionsTypesVersionsWildcard6 -TestSatisfiesOperatorCompletion +TestReferencesForExportedValues +TestReferencesInComment +TestReferencesInEmptyFile +TestReferencesForStatementKeywords +TestReferencesIsAvailableThroughGlobalNoCrash TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestStringLiteralTypeCompletionsInTypeArgForNonGeneric1 @@ -284,6 +306,7 @@ TestTripleSlashRefPathCompletionExtensionsAllowJSFalse TestTripleSlashRefPathCompletionExtensionsAllowJSTrue TestTripleSlashRefPathCompletionHiddenFile TestTripleSlashRefPathCompletionRootdirs +TestTslibFindAllReferencesOnRuntimeImportWithPaths1 TestTsxCompletion12 TestTsxCompletion13 TestTsxCompletion14 diff --git a/internal/fourslash/_scripts/tsconfig.json b/internal/fourslash/_scripts/tsconfig.json index 3337b2f1d7..2a320eaf55 100644 --- a/internal/fourslash/_scripts/tsconfig.json +++ b/internal/fourslash/_scripts/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "strict": true, "noEmit": true, - "module": "nodenext" + "module": "nodenext", + "allowImportingTsExtensions": true } } diff --git a/internal/fourslash/_scripts/updateFailing.mts b/internal/fourslash/_scripts/updateFailing.mts new file mode 100644 index 0000000000..f30e7462f2 --- /dev/null +++ b/internal/fourslash/_scripts/updateFailing.mts @@ -0,0 +1,32 @@ +import * as cp from "child_process"; +import * as fs from "fs"; +import path from "path"; +import which from "which"; +import { main as convertFourslash } from "./convertFourslash.mts"; + +const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt"); + +function main() { + fs.writeFileSync(failingTestsPath, "", "utf-8"); + convertFourslash(); + const go = which.sync("go"); + let testOutput: string; + try { + testOutput = cp.execFileSync(go, ["test", "./internal/fourslash/tests/gen"], { encoding: "utf-8" }); + } + catch (error) { + testOutput = (error as { stdout: string; }).stdout as string; + } + const regex = /--- FAIL: ([\S]+)/gm; + const failingTests: string[] = []; + let match; + + while ((match = regex.exec(testOutput)) !== null) { + failingTests.push(match[1]); + } + + fs.writeFileSync(failingTestsPath, failingTests.sort().join("\n") + "\n", "utf-8"); + convertFourslash(); +} + +main(); diff --git a/internal/fourslash/baselineutil.go b/internal/fourslash/baselineutil.go new file mode 100644 index 0000000000..db05e77a81 --- /dev/null +++ b/internal/fourslash/baselineutil.go @@ -0,0 +1,459 @@ +package fourslash + +import ( + "errors" + "fmt" + "io/fs" + "regexp" + "slices" + "strings" + + "github.com/microsoft/typescript-go/internal/collections" + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/vfs" +) + +type baselineFromTest struct { + content *strings.Builder + + baselineName, ext string +} + +func (b *baselineFromTest) addResult(command, actual string) { + // state.baseline(command, actual) in strada + if b.content.Len() != 0 { + b.content.WriteString("\n\n\n\n") + } + b.content.WriteString(`// === ` + command + " ===\n" + actual) +} + +func (b *baselineFromTest) getBaselineFileName() string { + return "fourslash/" + b.baselineName + b.ext +} + +type baselineFourslashLocationsOptions struct { + // markerInfo + marker *Marker // location + markerName string // name of the marker to be printed in baseline + + documentSpanId func(span *documentSpan) string + skipDocumentSpanDetails core.Tristate + skipDocumentContainingOnlyMarker core.Tristate + endMarker core.Tristate + + startMarkerPrefix func(span lsproto.Location) string + endMarkerSuffix func(span lsproto.Location) string + ignoredDocumentSpanProperties []string + additionalSpan *lsproto.Location +} + +func (f *FourslashTest) getBaselineForLocationsWithFileContents(spans []*lsproto.Location, options baselineFourslashLocationsOptions) string { + return f.getBaselineForGroupedLocationsWithFileContents(collections.GroupBy(spans, func(span *lsproto.Location) lsproto.DocumentUri { return span.Uri }), options) +} + +func (f *FourslashTest) getBaselineForGroupedLocationsWithFileContents(groupedLocations *collections.MultiMap[lsproto.DocumentUri, *lsproto.Location], options baselineFourslashLocationsOptions) string { + baselineEntries := []string{} + err := f.vfs.WalkDir("/", func(path string, d vfs.DirEntry, e error) error { + if e != nil { + return e + } + + if !d.Type().IsRegular() { + return nil + } + + locations := groupedLocations.Get(ls.FileNameToDocumentURI(path)) + if len(locations) == 0 { + return nil + } + + content, ok := f.vfs.ReadFile(path) + if !ok { + return nil + } + + documentSpans := core.Map(locations, func(location *lsproto.Location) *documentSpan { + return &documentSpan{ + Location: *location, + } + }) + baselineEntries = append(baselineEntries, f.getBaselineContentForFile(path, content, documentSpans, nil, options)) + return nil + }) + + if err != nil && !errors.Is(err, fs.ErrNotExist) { + panic("walkdir error during fourslash baseline: " + err.Error()) + } + // !!! foundMarker + // !!! foundAdditionalSpan + // !!! skipDocumentContainingOnlyMarker + + return strings.Join(baselineEntries, "\n\n") +} + +type documentSpan struct { + lsproto.Location + + // If the span represents a location that was remapped (e.g. via a .d.ts.map file), + // then the original filename and span will be specified here + originalLocation *lsproto.Location + + // If DocumentSpan.textSpan is the span for name of the declaration, + // then this is the span for relevant declaration + contextSpan *lsproto.Location + originalContextSpan *lsproto.Location +} + +type baselineDetail struct { + pos lsproto.Position + positionMarker string + span *documentSpan + kind string +} + +func (f *FourslashTest) getBaselineContentForFile( + fileName string, + content string, + spansInFile []*documentSpan, + spanToContextId map[documentSpan]int, + options baselineFourslashLocationsOptions, +) string { + details := []*baselineDetail{} + detailPrefixes := map[baselineDetail]string{} + detailSuffixes := map[baselineDetail]string{} + canDetermineContextIdInline := true + var groupedSpanForAdditionalSpan *documentSpan + + if options.marker != nil && options.marker.FileName() == fileName { + details = append(details, &baselineDetail{pos: options.marker.LSPosition, positionMarker: options.markerName}) + } + + for _, span := range spansInFile { + contextSpanIndex := len(details) + if span.contextSpan != nil { + details = append(details, &baselineDetail{pos: span.contextSpan.Range.Start, positionMarker: "<|", span: span, kind: "contextStart"}) + if canDetermineContextIdInline && ls.ComparePositions(span.contextSpan.Range.Start, span.Range.Start) > 0 { + // Need to do explicit pass to determine contextId since contextId starts after textStart + canDetermineContextIdInline = false + } + } + + textSpanIndex := len(details) + textSpanEnd := span.Range.End + details = append(details, + &baselineDetail{pos: span.Range.Start, positionMarker: "[|", span: span, kind: "textStart"}, + &baselineDetail{pos: span.Range.End, positionMarker: "|]", span: span, kind: "textEnd"}, + ) + + var contextSpanEnd *lsproto.Position + if span.contextSpan != nil { + contextSpanEnd = &span.contextSpan.Range.End + details = append(details, &baselineDetail{pos: span.contextSpan.Range.End, positionMarker: "|>", span: span, kind: "contextEnd"}) + } + + if options.additionalSpan != nil && span.Location == *options.additionalSpan { + groupedSpanForAdditionalSpan = span + } + + if options.startMarkerPrefix != nil { + if startPrefix := options.startMarkerPrefix(span.Location); startPrefix != "" { + if fileName == options.marker.FileName() && span.Range.Start == options.marker.LSPosition { + // ts.Debug.assert(!detailPrefixes.has(details[0]), "Expected only single prefix at marker location"); + detailPrefixes[*details[0]] = startPrefix + } else if span.contextSpan.Range.Start == span.Range.Start { + // Write it at contextSpan instead of textSpan + detailPrefixes[*details[contextSpanIndex]] = startPrefix + } else { + // At textSpan + detailPrefixes[*details[textSpanIndex]] = startPrefix + } + } + } + + if options.endMarkerSuffix != nil { + if endSuffix := options.endMarkerSuffix(span.Location); endSuffix != "" { + if fileName == options.marker.FileName() && textSpanEnd == options.marker.LSPosition { + // ts.Debug.assert(!detailSuffixes.has(details[0]), "Expected only single suffix at marker location"); + detailSuffixes[*details[0]] = endSuffix + } else if *contextSpanEnd == textSpanEnd { + // Write it at contextSpan instead of textSpan + detailSuffixes[*details[textSpanIndex+2]] = endSuffix + } else { + // At textSpan + detailSuffixes[*details[textSpanIndex+1]] = endSuffix + } + } + } + } + slices.SortStableFunc(details, func(d1, d2 *baselineDetail) int { + return ls.ComparePositions(d1.pos, d2.pos) + }) + // !!! if canDetermineContextIdInline + + textWithContext := newTextWithContext(fileName, content) + + // Our preferred way to write marker is + // /*MARKER*/[| some text |] + // [| some /*MARKER*/ text |] + // [| some text |]/*MARKER*/ + // Stable sort should handle first two cases but with that marker will be before rangeEnd if locations match + // So we will defer writing marker in this case by checking and finding index of rangeEnd if same + var deferredMarkerIndex *int + if options.documentSpanId == nil { + options.documentSpanId = func(span *documentSpan) string { return "" } + } + + for index, detail := range details { + if detail.span == nil && deferredMarkerIndex == nil { + // If this is marker position and its same as textEnd and/or contextEnd we want to write marker after those + for matchingEndPosIndex := index + 1; matchingEndPosIndex < len(details); matchingEndPosIndex++ { + // Defer after the location if its same as rangeEnd + if details[matchingEndPosIndex].pos == detail.pos && strings.HasSuffix(details[matchingEndPosIndex].kind, "End") { + deferredMarkerIndex = ptrTo(matchingEndPosIndex) + } + // Dont defer further than already determined + break + } + // Defer writing marker position to deffered marker index + if deferredMarkerIndex != nil { + continue + } + } + textWithContext.add(detail) + textWithContext.pos = detail.pos + // Prefix + prefix := detailPrefixes[*detail] + if prefix != "" { + textWithContext.newContent.WriteString(prefix) + } + textWithContext.newContent.WriteString(detail.positionMarker) + if detail.span != nil { + switch detail.kind { + case "textStart": + var text string + if options.skipDocumentSpanDetails.IsTrue() { + text = options.documentSpanId(detail.span) + } else { + text = convertDocumentSpanToString(detail.span, options.documentSpanId(detail.span), options.ignoredDocumentSpanProperties) + } + if groupedSpanForAdditionalSpan != nil && *(detail.span) == *groupedSpanForAdditionalSpan { + if text == "" { + text = `textSpan: true` + } else { + text = `textSpan: true` + `, ` + text + } + } + if contextId, ok := spanToContextId[*detail.span]; ok { + isAfterContextStart := false + for textStartIndex := index - 1; textStartIndex >= 0; textStartIndex-- { + textStartDetail := details[textStartIndex] + if textStartDetail.kind == "contextStart" && textStartDetail.span == detail.span { + isAfterContextStart = true + break + } + // Marker is ok to skip over + if textStartDetail.span != nil { + break + } + } + // Skip contextId on span thats surrounded by context span immediately + if !isAfterContextStart { + if text == "" { + text = fmt.Sprintf(`contextId: %v`, contextId) + } else { + text = fmt.Sprintf(`contextId: %v`, contextId) + `, ` + text + } + } + } + if text != "" { + textWithContext.newContent.WriteString(`{ ` + text + ` |}`) + } + case "contextStart": + if canDetermineContextIdInline { + spanToContextId[*detail.span] = len(spanToContextId) + } + } + + if deferredMarkerIndex != nil && *deferredMarkerIndex == index { + // Write the marker + textWithContext.newContent.WriteString(options.markerName) + deferredMarkerIndex = nil + detail = details[0] // Marker detail + } + } + if suffix, ok := detailSuffixes[*detail]; ok { + textWithContext.newContent.WriteString(suffix) + } + } + textWithContext.add(nil) + if textWithContext.newContent.Len() != 0 { + textWithContext.readableContents.WriteString("\n") + textWithContext.readableJsoncBaseline(textWithContext.newContent.String()) + } + return textWithContext.readableContents.String() +} + +func convertDocumentSpanToString(location *documentSpan, prefix string, ignoredProperties []string) string { + // !!! + return prefix +} + +var lineSplitter = regexp.MustCompile(`\r?\n`) + +type textWithContext struct { + nLinesContext int // number of context lines to write to baseline + + readableContents *strings.Builder // builds what will be returned to be written to baseline + + newContent *strings.Builder // helper; the part of the original file content to write between details + pos lsproto.Position + isLibFile bool + fileName string + content string // content of the original file + lineStarts *ls.LineMap + converters *ls.Converters + + // posLineInfo + posInfo *lsproto.Position + lineInfo int +} + +// implements ls.Script +func (t *textWithContext) FileName() string { + return t.fileName +} + +// implements ls.Script +func (t *textWithContext) Text() string { + return t.content +} + +func newTextWithContext(fileName string, content string) *textWithContext { + t := &textWithContext{ + nLinesContext: 4, + + readableContents: &strings.Builder{}, + + isLibFile: regexp.MustCompile(`lib.*\.d\.ts$`).MatchString(fileName), + newContent: &strings.Builder{}, + pos: lsproto.Position{Line: 0, Character: 0}, + fileName: fileName, + content: content, + lineStarts: ls.ComputeLineStarts(content), + } + + t.converters = ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(_ string) *ls.LineMap { + return t.lineStarts + }) + t.readableContents.WriteString("// === " + fileName + " ===\n") + return t +} + +func (t *textWithContext) add(detail *baselineDetail) { + if t.content == "" && detail == nil { + panic("Unsupported") + } + if detail == nil || (detail.kind != "textEnd" && detail.kind != "contextEnd") { + // Calculate pos to location number of lines + posLineIndex := t.lineInfo + if t.posInfo == nil || *t.posInfo != t.pos { + posLineIndex = t.lineStarts.ComputeIndexOfLineStart(t.converters.LineAndCharacterToPosition(t, t.pos)) + } + + locationLineIndex := len(t.lineStarts.LineStarts) - 1 + if detail != nil { + locationLineIndex = t.lineStarts.ComputeIndexOfLineStart(t.converters.LineAndCharacterToPosition(t, detail.pos)) + t.posInfo = &detail.pos + t.lineInfo = locationLineIndex + } + + nLines := 0 + if t.newContent.Len() != 0 { + nLines += t.nLinesContext + 1 + } + if detail != nil { + nLines += t.nLinesContext + 1 + } + // first nLinesContext and last nLinesContext + if locationLineIndex-posLineIndex > nLines { + if t.newContent.Len() != 0 { + var skippedString string + if t.isLibFile { + skippedString = "--- (line: --) skipped ---\n" + } else { + skippedString = fmt.Sprintf(`// --- (line: %v) skipped ---`, posLineIndex+t.nLinesContext+1) + } + + t.readableContents.WriteString("\n") + t.readableJsoncBaseline(t.newContent.String() + t.sliceOfContent( + t.getIndex(t.pos), + t.getIndex(t.lineStarts.LineStarts[posLineIndex+t.nLinesContext]), + ) + skippedString) + + if detail != nil { + t.readableContents.WriteString("\n") + } + t.newContent.Reset() + } + if detail != nil { + if t.isLibFile { + t.newContent.WriteString("--- (line: --) skipped ---\n") + } else { + t.newContent.WriteString(fmt.Sprintf("--- (line: %v) skipped ---\n", locationLineIndex-t.nLinesContext+1)) + } + t.newContent.WriteString(t.sliceOfContent( + t.getIndex(t.lineStarts.LineStarts[locationLineIndex-t.nLinesContext+1]), + t.getIndex(detail.pos), + )) + } + return + } + } + if detail == nil { + t.newContent.WriteString(t.sliceOfContent(t.getIndex(t.pos), nil)) + } else { + t.newContent.WriteString(t.sliceOfContent(t.getIndex(t.pos), t.getIndex(detail.pos))) + } +} + +func (t *textWithContext) readableJsoncBaseline(text string) { + for _, line := range lineSplitter.Split(text, -1) { + t.readableContents.WriteString(`// ` + line + "\n") + } +} + +func (t *textWithContext) sliceOfContent(start *int, end *int) string { + if start == nil || *start < 0 { + start = ptrTo(0) + } + + if end == nil || *end > len(t.content) { + end = ptrTo(len(t.content)) + } + + if *start > *end { + return "" + } + + return t.content[*start:*end] +} + +func (t *textWithContext) getIndex(i interface{}) *int { + switch i.(type) { + case *int: + return i.(*int) + case int: + return ptrTo(i.(int)) + case core.TextPos: + return ptrTo(int(i.(core.TextPos))) + case *core.TextPos: + return ptrTo(int(*i.(*core.TextPos))) + case lsproto.Position: + return t.getIndex(t.converters.LineAndCharacterToPosition(t, i.(lsproto.Position))) + case *lsproto.Position: + return t.getIndex(t.converters.LineAndCharacterToPosition(t, *i.(*lsproto.Position))) + } + panic(fmt.Sprintf("getIndex: unsupported type %T", i)) +} diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index d9c5b9b9ff..5cb6485000 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -3,6 +3,8 @@ package fourslash import ( "fmt" "io" + "maps" + "slices" "strings" "testing" "unicode" @@ -17,6 +19,7 @@ import ( "github.com/microsoft/typescript-go/internal/lsp" "github.com/microsoft/typescript-go/internal/lsp/lsproto" "github.com/microsoft/typescript-go/internal/project" + "github.com/microsoft/typescript-go/internal/testutil/baseline" "github.com/microsoft/typescript-go/internal/testutil/harnessutil" "github.com/microsoft/typescript-go/internal/tspath" "github.com/microsoft/typescript-go/internal/vfs" @@ -32,12 +35,13 @@ type FourslashTest struct { vfs vfs.FS testData *TestData // !!! consolidate test files from test data and script info + baseline *baselineFromTest scriptInfos map[string]*scriptInfo converters *ls.Converters currentCaretPosition lsproto.Position - lastKnownMarkerName string + lastKnownMarkerName *string activeFilename string selectionEnd *lsproto.Position } @@ -127,13 +131,14 @@ func (c *parsedFileCache) CacheFile(opts ast.SourceFileParseOptions, text string var _ project.ParsedFileCache = (*parsedFileCache)(nil) +const rootDir = "/" + func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, content string) *FourslashTest { if !bundled.Embedded { // Without embedding, we'd need to read all of the lib files out from disk into the MapFS. // Just skip this for now. t.Skip("bundled files are not embedded") } - rootDir := "/" fileName := getFileNameFromTest(t) testfs := make(map[string]string) scriptInfos := make(map[string]*scriptInfo) @@ -159,7 +164,6 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten Err: &err, Cwd: "/", - NewLine: core.NewLineKindLF, FS: fs, DefaultLibraryPath: bundled.LibPath(), @@ -293,12 +297,21 @@ func (f *FourslashTest) readMsg(t *testing.T) *lsproto.Message { return msg } +func (f *FourslashTest) GoToMarkerOrRange(t *testing.T, markerOrRange MarkerOrRange) { + // GoToRangeStart + f.goToMarker(t, markerOrRange.GetMarker()) +} + func (f *FourslashTest) GoToMarker(t *testing.T, markerName string) { marker, ok := f.testData.MarkerPositions[markerName] if !ok { - t.Fatalf("Marker %s not found", markerName) + t.Fatalf("Marker '%s' not found", markerName) } - f.ensureActiveFile(t, marker.FileName) + f.goToMarker(t, marker) +} + +func (f *FourslashTest) goToMarker(t *testing.T, marker *Marker) { + f.ensureActiveFile(t, marker.FileName()) f.goToPosition(t, marker.LSPosition) f.lastKnownMarkerName = marker.Name } @@ -310,11 +323,89 @@ func (f *FourslashTest) GoToEOF(t *testing.T) { f.goToPosition(t, LSPPos) } +func (f *FourslashTest) GoToBOF(t *testing.T) { + f.goToPosition(t, lsproto.Position{Line: 0, Character: 0}) +} + +func (f *FourslashTest) GoToPosition(t *testing.T, position int) { + script := f.getScriptInfo(f.activeFilename) + LSPPos := f.converters.PositionToLineAndCharacter(script, core.TextPos(position)) + f.goToPosition(t, LSPPos) +} + func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { f.currentCaretPosition = position f.selectionEnd = nil } +func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(t *testing.T, marker *Marker, index int)) { + var markers []*Marker + if len(markers) == 0 { + markers = f.Markers() + } else { + markers = make([]*Marker, 0, len(markerNames)) + for _, name := range markerNames { + marker, ok := f.testData.MarkerPositions[name] + if !ok { + t.Fatalf("Marker '%s' not found", name) + } + markers = append(markers, marker) + } + } + for i, marker := range markers { + f.goToMarker(t, marker) + action(t, marker, i) + } +} + +func (f *FourslashTest) GoToEachRange(t *testing.T, action func(t *testing.T, rangeMarker *RangeMarker)) { + ranges := f.Ranges() + for _, rangeMarker := range ranges { + f.goToPosition(t, rangeMarker.LSRange.Start) + action(t, rangeMarker) + } +} + +func (f *FourslashTest) GoToRangeStart(t *testing.T, rangeMarker *RangeMarker) { + f.openFile(t, rangeMarker.FileName()) + f.goToPosition(t, rangeMarker.LSRange.Start) +} + +func (f *FourslashTest) GoToSelect(t *testing.T, startMarkerName string, endMarkerName string) { + startMarker := f.testData.MarkerPositions[startMarkerName] + if startMarker == nil { + t.Fatalf("Start marker '%s' not found", startMarkerName) + } + endMarker := f.testData.MarkerPositions[endMarkerName] + if endMarker == nil { + t.Fatalf("End marker '%s' not found", endMarkerName) + } + if startMarker.FileName() != endMarker.FileName() { + t.Fatalf("Markers '%s' and '%s' are in different files", startMarkerName, endMarkerName) + } + f.ensureActiveFile(t, startMarker.FileName()) + f.goToPosition(t, startMarker.LSPosition) + f.selectionEnd = &endMarker.LSPosition +} + +func (f *FourslashTest) GoToSelectRange(t *testing.T, rangeMarker *RangeMarker) { + f.GoToRangeStart(t, rangeMarker) + f.selectionEnd = &rangeMarker.LSRange.End +} + +func (f *FourslashTest) GoToFile(t *testing.T, filename string) { + filename = tspath.GetNormalizedAbsolutePath(filename, rootDir) + f.openFile(t, filename) +} + +func (f *FourslashTest) GoToFileNumber(t *testing.T, index int) { + if index < 0 || index >= len(f.testData.Files) { + t.Fatalf("File index %d out of range (0-%d)", index, len(f.testData.Files)-1) + } + filename := f.testData.Files[index].fileName + f.openFile(t, filename) +} + func (f *FourslashTest) Markers() []*Marker { return f.testData.Markers } @@ -344,6 +435,15 @@ func (f *FourslashTest) openFile(t *testing.T, filename string) { }) } +func (f *FourslashTest) currentTextDocumentPositionParams() lsproto.TextDocumentPositionParams { + return lsproto.TextDocumentPositionParams{ + TextDocument: lsproto.TextDocumentIdentifier{ + Uri: ls.FileNameToDocumentURI(f.activeFilename), + }, + Position: f.currentCaretPosition, + } +} + func getLanguageKind(filename string) lsproto.LanguageKind { if tspath.FileExtensionIsOneOf( filename, @@ -392,11 +492,11 @@ type CompletionsExpectedItemDefaults struct { // *lsproto.CompletionItem | string type CompletionsExpectedItem = any -// !!! unsorted completions type CompletionsExpectedItems struct { Includes []CompletionsExpectedItem Excludes []string Exact []CompletionsExpectedItem + Unsorted []CompletionsExpectedItem } // string | *Marker | []string | []*Marker @@ -404,20 +504,23 @@ type MarkerInput = any // !!! user preferences param // !!! completion context param -// !!! go to marker: use current marker if none specified/support nil marker input func (f *FourslashTest) VerifyCompletions(t *testing.T, markerInput MarkerInput, expected *CompletionsExpectedList) { switch marker := markerInput.(type) { case string: - f.verifyCompletionsAtMarker(t, marker, expected) + f.GoToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) case *Marker: - f.verifyCompletionsAtMarker(t, marker.Name, expected) + f.goToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) case []string: for _, markerName := range marker { - f.verifyCompletionsAtMarker(t, markerName, expected) + f.GoToMarker(t, markerName) + f.verifyCompletionsWorker(t, expected) } case []*Marker: for _, marker := range marker { - f.verifyCompletionsAtMarker(t, marker.Name, expected) + f.goToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) } case nil: f.verifyCompletionsWorker(t, expected) @@ -426,36 +529,37 @@ func (f *FourslashTest) VerifyCompletions(t *testing.T, markerInput MarkerInput, } } -func (f *FourslashTest) verifyCompletionsAtMarker(t *testing.T, markerName string, expected *CompletionsExpectedList) { - f.GoToMarker(t, markerName) - f.verifyCompletionsWorker(t, expected) -} - func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *CompletionsExpectedList) { + var prefix string + if f.lastKnownMarkerName != nil { + prefix = fmt.Sprintf("At marker '%s': ", *f.lastKnownMarkerName) + } else { + prefix = fmt.Sprintf("At position (Ln %d, Col %d): ", f.currentCaretPosition.Line, f.currentCaretPosition.Character) + } params := &lsproto.CompletionParams{ - TextDocumentPositionParams: lsproto.TextDocumentPositionParams{ - TextDocument: lsproto.TextDocumentIdentifier{ - Uri: ls.FileNameToDocumentURI(f.activeFilename), - }, - Position: f.currentCaretPosition, - }, - Context: &lsproto.CompletionContext{}, + TextDocumentPositionParams: f.currentTextDocumentPositionParams(), + Context: &lsproto.CompletionContext{}, } resMsg := f.sendRequest(t, lsproto.MethodTextDocumentCompletion, params) if resMsg == nil { - t.Fatalf("Nil response received for completion request at marker %s", f.lastKnownMarkerName) + t.Fatalf(prefix+"Nil response received for completion request", f.lastKnownMarkerName) } result := resMsg.AsResponse().Result switch result := result.(type) { case *lsproto.CompletionList: - verifyCompletionsResult(t, f.lastKnownMarkerName, result, expected) + f.verifyCompletionsResult(t, f.currentCaretPosition, result, expected, prefix) default: - t.Fatalf("Unexpected response type for completion request at marker %s: %v", f.lastKnownMarkerName, result) + t.Fatalf(prefix+"Unexpected response type for completion request: %v", result) } } -func verifyCompletionsResult(t *testing.T, markerName string, actual *lsproto.CompletionList, expected *CompletionsExpectedList) { - prefix := fmt.Sprintf("At marker '%s': ", markerName) +func (f *FourslashTest) verifyCompletionsResult( + t *testing.T, + position lsproto.Position, + actual *lsproto.CompletionList, + expected *CompletionsExpectedList, + prefix string, +) { if actual == nil { if !isEmptyExpectedList(expected) { t.Fatal(prefix + "Expected completion list but got nil.") @@ -520,6 +624,9 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl if expected.Excludes != nil { t.Fatal(prefix + "Expected exact completion list but also specified 'excludes'.") } + if expected.Unsorted != nil { + t.Fatal(prefix + "Expected exact completion list but also specified 'unsorted'.") + } if len(actual) != len(expected.Exact) { t.Fatalf(prefix+"Expected %d exact completion items but got %d: %s", len(expected.Exact), len(actual), cmp.Diff(actual, expected.Exact)) } @@ -532,6 +639,38 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl for _, item := range actual { nameToActualItem[item.Label] = item } + if expected.Unsorted != nil { + if expected.Includes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'includes'.") + } + if expected.Excludes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'excludes'.") + } + for _, item := range expected.Unsorted { + switch item := item.(type) { + case string: + _, ok := nameToActualItem[item] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item) + case *lsproto.CompletionItem: + actualItem, ok := nameToActualItem[item.Label] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item.Label, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item.Label) + verifyCompletionItem(t, prefix+"Includes completion item mismatch for label "+item.Label, actualItem, item) + default: + t.Fatalf("%sExpected completion item to be a string or *lsproto.CompletionItem, got %T", prefix, item) + } + } + if len(expected.Unsorted) != len(actual) { + unmatched := slices.Collect(maps.Keys(nameToActualItem)) + t.Fatalf("%sAdditional completions found but not included in 'unsorted': %s", prefix, strings.Join(unmatched, "\n")) + } + return + } if expected.Includes != nil { for _, item := range expected.Includes { switch item := item.(type) { @@ -615,6 +754,71 @@ 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("Error during test '%s': Another baseline is already in progress", t.Name()) + } else { + f.baseline = &baselineFromTest{ + content: &strings.Builder{}, + baselineName: "findAllRef/" + strings.TrimPrefix(t.Name(), "Test"), + ext: ".baseline.jsonc", + } + } + + // empty baseline after test completes + defer func() { + f.baseline = nil + }() + + for _, markerOrRange := range referenceLocations { + // worker in `baselineEachMarkerOrRange` + f.GoToMarkerOrRange(t, markerOrRange) + params := &lsproto.ReferenceParams{ + TextDocumentPositionParams: f.currentTextDocumentPositionParams(), + Context: &lsproto.ReferenceContext{}, + } + resMsg := f.sendRequest(t, lsproto.MethodTextDocumentReferences, params) + if resMsg == nil { + if f.lastKnownMarkerName == nil { + t.Fatalf("Unexpected references response type at pos %v", f.currentCaretPosition) + } else { + t.Fatalf("Nil response received for references request at marker '%s'", *f.lastKnownMarkerName) + } + } + result := resMsg.AsResponse().Result + if result, ok := result.([]*lsproto.Location); ok { + f.baseline.addResult("findAllReferences", f.getBaselineForLocationsWithFileContents(result, baselineFourslashLocationsOptions{ + marker: markerOrRange.GetMarker(), + markerName: "/*FIND ALL REFS*/", + })) + } else { + if f.lastKnownMarkerName == nil { + t.Fatalf("Unexpected references response type at pos %v: %T", f.currentCaretPosition, result) + } else { + t.Fatalf("Unexpected references response type at marker '%s': %T", *f.lastKnownMarkerName, result) + } + } + } + baseline.Run(t, f.baseline.getBaselineFileName(), f.baseline.content.String(), baseline.Options{}) +} + func ptrTo[T any](v T) *T { return &v } @@ -727,13 +931,13 @@ func (f *FourslashTest) typeText(t *testing.T, text string) { func (f *FourslashTest) editScriptAndUpdateMarkers(t *testing.T, fileName string, editStart int, editEnd int, newText string) { script := f.editScript(t, fileName, editStart, editEnd, newText) for _, marker := range f.testData.Markers { - if marker.FileName == fileName { + if marker.FileName() == fileName { marker.Position = updatePosition(marker.Position, editStart, editEnd, newText) marker.LSPosition = f.converters.PositionToLineAndCharacter(script, core.TextPos(marker.Position)) } } for _, rangeMarker := range f.testData.Ranges { - if rangeMarker.FileName == fileName { + if rangeMarker.FileName() == fileName { start := updatePosition(rangeMarker.Range.Pos(), editStart, editEnd, newText) end := updatePosition(rangeMarker.Range.End(), editStart, editEnd, newText) rangeMarker.Range = core.NewTextRange(start, end) diff --git a/internal/fourslash/test_parser.go b/internal/fourslash/test_parser.go index 1b84be0181..12cef16d67 100644 --- a/internal/fourslash/test_parser.go +++ b/internal/fourslash/test_parser.go @@ -27,14 +27,44 @@ type RangeMarker struct { LSRange lsproto.Range } +func (r *RangeMarker) LSPos() lsproto.Position { + return r.LSRange.Start +} + +func (r *RangeMarker) FileName() string { + return r.fileName +} + +func (r *RangeMarker) GetMarker() *Marker { + return r.Marker +} + type Marker struct { - FileName string + fileName string Position int LSPosition lsproto.Position - Name string + Name *string // `nil` for anonymous markers such as `{| "foo": "bar" |}` Data map[string]interface{} } +func (m *Marker) LSPos() lsproto.Position { + return m.LSPosition +} + +func (m *Marker) FileName() string { + return m.fileName +} + +func (m *Marker) GetMarker() *Marker { + return m +} + +type MarkerOrRange interface { + FileName() string + LSPos() lsproto.Position + GetMarker() *Marker +} + type TestData struct { Files []*TestFileInfo MarkerPositions map[string]*Marker @@ -75,10 +105,17 @@ func ParseTestData(t *testing.T, contents string, fileName string) TestData { markers = append(markers, file.markers...) ranges = append(ranges, file.ranges...) for _, marker := range file.markers { - if _, ok := markerPositions[marker.Name]; ok { - t.Fatalf("Duplicate marker name: %s", marker.Name) + if marker.Name == nil { + if marker.Data != nil { + // The marker is an anonymous object marker, which does not need a name. Markers are only set into markerPositions if they have a name + continue + } + t.Fatalf(`Marker at position %v is unnamed`, marker.Position) } - markerPositions[marker.Name] = marker + if existing, ok := markerPositions[*marker.Name]; ok { + t.Fatalf(`Duplicate marker name: "%s" at %v and %v`, *marker.Name, marker.Position, existing.Position) + } + markerPositions[*marker.Name] = marker } } @@ -211,8 +248,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,9 +308,9 @@ 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, + Name: &markerNameText, } if len(openRanges) > 0 { openRanges[len(openRanges)-1].marker = marker @@ -372,7 +411,7 @@ func getObjectMarker(fileName string, location *locationInformation, text string } marker := &Marker{ - FileName: fileName, + fileName: fileName, Position: location.position, Data: markerValue, } @@ -380,7 +419,7 @@ func getObjectMarker(fileName string, location *locationInformation, text string // Object markers can be anonymous if markerValue["name"] != nil { if name, ok := markerValue["name"].(string); ok && name != "" { - marker.Name = name + marker.Name = &name } } diff --git a/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go new file mode 100644 index 0000000000..c728bd7434 --- /dev/null +++ b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "strings" + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInUnclosedTypeArguments(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let x = 10; +type Type = void; +declare function f(): void; +declare function f2(): void; +f +f +f(); + +f2 +f2 +f2(); + +f2/*4x*/T/*5x*/y/*6x*/ +f2<() =>/*1y*/T/*2y*/y/*3y*/, () =>/*4y*/T/*5y*/y/*6y*/ +f2/*1z*/T/*2z*/y/*3z*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEachMarker(t, nil, func(t *testing.T, marker *fourslash.Marker, index int) { + markerName := marker.Name + valueOnly := markerName != nil && strings.HasSuffix(*markerName, "ValueOnly") + commitCharacters := &defaultCommitCharacters + if marker.Data != nil { + newId := marker.Data["newId"] + typeOnly := marker.Data["typeOnly"] + if newId != nil && newId.(bool) && !(typeOnly != nil && typeOnly.(bool)) { + commitCharacters = &[]string{".", ";"} + } + } + var includes []fourslash.CompletionsExpectedItem + var excludes []string + if valueOnly { + includes = []fourslash.CompletionsExpectedItem{ + "x", + } + excludes = []string{ + "Type", + } + } else { + includes = []fourslash.CompletionsExpectedItem{ + "Type", + } + excludes = []string{ + "x", + } + } + f.VerifyCompletions(t, marker, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: commitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: includes, + Excludes: excludes, + }, + }) + }) +} diff --git a/internal/fourslash/tests/gen/addDuplicateSetter_test.go b/internal/fourslash/tests/gen/addDuplicateSetter_test.go new file mode 100644 index 0000000000..8bb94a2008 --- /dev/null +++ b/internal/fourslash/tests/gen/addDuplicateSetter_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 TestAddDuplicateSetter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + set foo(value) { } + /**/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "set foo(value) { }") +} diff --git a/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_test.go b/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_test.go new file mode 100644 index 0000000000..d6d47126f9 --- /dev/null +++ b/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_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 TestAddFunctionAboveMultiLineLambdaExpression(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +() => + // do something +0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "function Foo() { }") +} diff --git a/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_test.go b/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_test.go new file mode 100644 index 0000000000..3fcf0ddd7e --- /dev/null +++ b/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_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 TestAddInterfaceToNotSatisfyConstraint(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + a: number; +} +/**/ +interface C { + x: T; +} + +var v2: C; // should not work` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "interface B { b: string; }") +} diff --git a/internal/fourslash/tests/gen/aliasToVarUsedAsType_test.go b/internal/fourslash/tests/gen/aliasToVarUsedAsType_test.go new file mode 100644 index 0000000000..bf5faeb5e9 --- /dev/null +++ b/internal/fourslash/tests/gen/aliasToVarUsedAsType_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 TestAliasToVarUsedAsType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +module A { +export var X; +import Z = A.X; +var v: Z; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} 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/autoImportProvider_referencesCrash_test.go b/internal/fourslash/tests/gen/autoImportProvider_referencesCrash_test.go new file mode 100644 index 0000000000..4189016e57 --- /dev/null +++ b/internal/fourslash/tests/gen/autoImportProvider_referencesCrash_test.go @@ -0,0 +1,44 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAutoImportProvider_referencesCrash(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /home/src/workspaces/project/a/package.json +{} +// @Filename: /home/src/workspaces/project/a/tsconfig.json +{} +// @Filename: /home/src/workspaces/project/a/index.ts +class A {} +// @Filename: /home/src/workspaces/project/a/index.d.ts +declare class A { +} +//# sourceMappingURL=index.d.ts.map +// @Filename: /home/src/workspaces/project/a/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC;CAAG"} +// @Filename: /home/src/workspaces/project/b/tsconfig.json +{ + "compilerOptions": { "disableSourceOfProjectReferenceRedirect": true }, + "references": [{ "path": "../a" }] +} +// @Filename: /home/src/workspaces/project/b/b.ts +/// +new A/**/(); +// @Filename: /home/src/workspaces/project/c/package.json +{ "dependencies": { "a": "*" } } +// @Filename: /home/src/workspaces/project/c/tsconfig.json +{ "references" [{ "path": "../a" }] } +// @Filename: /home/src/workspaces/project/c/index.ts +export {}; +// @link: /home/src/workspaces/project/a -> /home/src/workspaces/project/c/node_modules/a` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/home/src/workspaces/project/c/index.ts") + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/basicClassMembers_test.go b/internal/fourslash/tests/gen/basicClassMembers_test.go new file mode 100644 index 0000000000..d160527da4 --- /dev/null +++ b/internal/fourslash/tests/gen/basicClassMembers_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 TestBasicClassMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class n { + constructor (public x: number, public y: number, private z: string) { } +} +var t = new n(0, 1, '');` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEOF(t) + f.Insert(t, "t.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"x", "y"}, + Excludes: []string{"z"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionAfterNewline2_test.go b/internal/fourslash/tests/gen/completionAfterNewline2_test.go index 0a0ccd2120..05873a7df0 100644 --- a/internal/fourslash/tests/gen/completionAfterNewline2_test.go +++ b/internal/fourslash/tests/gen/completionAfterNewline2_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionAfterNewline2(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let foo = 5 as const /*1*/ /*2*/` diff --git a/internal/fourslash/tests/gen/completionAfterNewline_test.go b/internal/fourslash/tests/gen/completionAfterNewline_test.go index c64f858811..69832aa4f5 100644 --- a/internal/fourslash/tests/gen/completionAfterNewline_test.go +++ b/internal/fourslash/tests/gen/completionAfterNewline_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionAfterNewline(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let foo /*1*/ /*2*/ diff --git a/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go new file mode 100644 index 0000000000..0d84561e68 --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go @@ -0,0 +1,64 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteralRelativeImport5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @rootDirs: /repo/src1,/repo/src2/,/repo/generated1,/repo/generated2/ +// @Filename: /dir/secret_file.ts +/*secret_file*/ +// @Filename: /repo/src1/dir/test1.ts +import * as foo1 from ".//*import_as1*/ +import foo2 = require(".//*import_equals1*/ +var foo3 = require(".//*require1*/ +// @Filename: /repo/src2/dir/test2.ts +import * as foo1 from "..//*import_as2*/ +import foo2 = require("..//*import_equals2*/ +var foo3 = require("..//*require2*/ +// @Filename: /repo/src2/index.ts +import * as foo1 from ".//*import_as3*/ +import foo2 = require(".//*import_equals3*/ +var foo3 = require(".//*require3*/ +// @Filename: /repo/generated1/dir/f1.ts +/*f1*/ +// @Filename: /repo/generated2/dir/f2.ts +/*f2*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"import_as1", "import_equals1", "require1"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"f1", "f2", "test2"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as2", "import_equals2", "require2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir", "index"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as3", "import_equals3", "require3"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go new file mode 100644 index 0000000000..9835af9244 --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteral_quotePreference7(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +export const a = null; +// @filename: /b.ts +import { a } from './a'; + +const foo = { '#': null }; +foo[|./**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/b.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Label: "#", InsertText: ptrTo("['#']")}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go new file mode 100644 index 0000000000..122a3ec06a --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteral_quotePreference8(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +export const a = null; +// @filename: /b.ts +import { a } from './a'; + +const foo = { '"a name\'s all good but it\'s better with more"': null }; +foo[|./**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/b.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Label: "\"a name's all good but it's better with more\"", InsertText: ptrTo("['\"a name\\'s all good but it\\'s better with more\"']")}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAtEOF1_test.go b/internal/fourslash/tests/gen/completionListAtEOF1_test.go new file mode 100644 index 0000000000..4fb15e54a1 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAtEOF1_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 TestCompletionListAtEOF1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if(0 === ''.` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEOF(t) + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"charAt"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAtEOF2_test.go b/internal/fourslash/tests/gen/completionListAtEOF2_test.go new file mode 100644 index 0000000000..8ddc7009ae --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAtEOF2_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 TestCompletionListAtEOF2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Shapes { + export class Point { + constructor(public x: number, public y: number) { } + } +} +var p = { + /**/ + var q = n; +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "it") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"items"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go index f7d4ca6ea0..3daf1f08ed 100644 --- a/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go +++ b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInFunctionDeclaration(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var a = 0; function foo(/**/` diff --git a/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go new file mode 100644 index 0000000000..a92f598b99 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go @@ -0,0 +1,70 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInObjectBindingPattern15(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + private xxx1 = 1; + protected xxx2 = 2; + public xxx3 = 3; + private static xxx4 = 4; + protected static xxx5 = 5; + public static xxx6 = 6; + foo() { + const { /*1*/ } = this; + const { /*2*/ } = Foo; + } +} + +const { /*3*/ } = new Foo(); +const { /*4*/ } = Foo;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx1", "xxx2", "xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx4", "xxx5", "xxx6"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx6"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go new file mode 100644 index 0000000000..66ced94e46 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_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 TestCompletionListInTypeLiteralInTypeParameter1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Foo { + one: string; + two: number; + 333: symbol; + '4four': boolean; + '5 five': object; + number: string; + Object: number; +} + +interface Bar { + foo: T; +} + +var foobar: Bar<{/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"one", "two", "\"333\"", "\"4four\"", "\"5 five\"", "number", "Object"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go b/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go index 9ceb4be3b3..e273ca809d 100644 --- a/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go +++ b/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInUnclosedFunction10(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface MyType { } diff --git a/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go b/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go index 1136bb85da..eb8e376e90 100644 --- a/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go +++ b/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInUnclosedFunction11(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface MyType { } diff --git a/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go new file mode 100644 index 0000000000..afe0a1e5bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInstanceProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + private privateMethod() { } + private privateProperty; + + protected protectedMethod() { } + protected protectedProperty; + + public publicMethod() { } + public publicProperty; + + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; + + test() { + this./*1*/; + + var b: Base; + var c: C1; + + b./*2*/; + c./*3*/; + } +} + +class C1 extends Base { + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "protectedOverriddenMethod", "protectedOverriddenProperty", "test"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "test"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListModuleMembers_test.go b/internal/fourslash/tests/gen/completionListModuleMembers_test.go new file mode 100644 index 0000000000..616665fce4 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListModuleMembers_test.go @@ -0,0 +1,55 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListModuleMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` module Module { + var innerVariable = 1; + function innerFunction() { } + class innerClass { } + module innerModule { } + interface innerInterface {} + export var exportedVariable = 1; + export function exportedFunction() { } + export class exportedClass { } + export module exportedModule { export var exportedInnerModuleVariable = 1; } + export interface exportedInterface {} + } + +Module./*ValueReference*/; + +var x : Module./*TypeReference*/ + +class TestClass extends Module./*TypeReferenceInExtendsList*/ { } + +interface TestInterface implements Module./*TypeReferenceInImplementsList*/ { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"ValueReference", "TypeReferenceInExtendsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedFunction", "exportedVariable", "exportedClass", "exportedModule"}, + }, + }) + f.VerifyCompletions(t, []string{"TypeReference", "TypeReferenceInImplementsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedClass", "exportedInterface"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go new file mode 100644 index 0000000000..0c5dd0d3bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go @@ -0,0 +1,66 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListOfSplitInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + a: number; +} +interface I extends A { + i1: number; +} +interface I1 extends A { + i11: number; +} +interface B { + b: number; +} +interface B1 { + b1: number; +} +interface I extends B { + i2: number; +} +interface I1 extends B, B1 { + i12: number; +} +interface C { + c: number; +} +interface I extends C { + i3: number; +} +var ci: I; +ci./*1*/b; +var ci1: I1; +ci1./*2*/b;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"i1", "i2", "i3", "a", "b", "c"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"i11", "i12", "a", "b", "b1"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOnAliases2_test.go b/internal/fourslash/tests/gen/completionListOnAliases2_test.go new file mode 100644 index 0000000000..f3938d9391 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOnAliases2_test.go @@ -0,0 +1,120 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListOnAliases2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export interface I { } + export class C { + static property; + } + export enum E { + value = 0 + } + export module N { + export var v; + } + export var V = 0; + export function F() { } + export import A = M; +} + +import m = M; +import c = M.C; +import e = M.E; +import n = M.N; +import v = M.V; +import f = M.F; +import a = M.A; + +m./*1*/; +var tmp: m./*1Type*/; +c./*2*/; +e./*3*/; +n./*4*/; +v./*5*/; +f./*6*/; +a./*7*/; +var tmp2: a./*7Type*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "7"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"F", "C", "E", "N", "V", "A"}, + }, + }) + f.VerifyCompletions(t, []string{"1Type", "7Type"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"I", "C", "E", "A"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus([]fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "property"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}}), + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"value"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"v"}, + }, + }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"toFixed"}, + }, + }) + f.VerifyCompletions(t, "6", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"call"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go new file mode 100644 index 0000000000..104f295b76 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go @@ -0,0 +1,83 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesAccessors(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + get #x() { return 1 }; + set #x(value: number) { }; + y() {}; + } + class Bar extends Foo { + get #z() { return 1 }; + set #z(value: number) { }; + t() {}; + l; + constructor() { + this./*1*/ + class Baz { + get #z() { return 1 }; + set #z(value: number) { }; + get #u() { return 1 }; + set #u(value: number) { }; + v() {}; + k; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v", "k"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go new file mode 100644 index 0000000000..a52f1bec69 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesMethods(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + #x() {}; + y() {}; + } + class Bar extends Foo { + #z() {}; + t() {}; + constructor() { + this./*1*/ + class Baz { + #z() {}; + #u() {}; + v() {}; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNames_test.go b/internal/fourslash/tests/gen/completionListPrivateNames_test.go new file mode 100644 index 0000000000..0f23424e47 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNames_test.go @@ -0,0 +1,78 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNames(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + #x; + y; +} + +class Bar extends Foo { + #z; + t; + constructor() { + this./*1*/ + class Baz { + #z; + #u; + v; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } +} + +new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go new file mode 100644 index 0000000000..be5d12d598 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go @@ -0,0 +1,73 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + protected y; + constructor(protected x) {} + method() { this./*1*/; } +} +class D1 extends Base { + protected z; + method1() { this./*2*/; } +} +class D2 extends Base { + method2() { this./*3*/; } +} +class D3 extends D1 { + method2() { this./*4*/; } +} +var b: Base; +f./*5*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "5", nil) +} diff --git a/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go b/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go new file mode 100644 index 0000000000..ffd1a9a75c --- /dev/null +++ b/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsAfterLessThanToken(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f() { + const k: Record { + foo(): T; +} +function foo(/**/): string { return null; } +function foo(x: T): T { return null; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "x: string") +} 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/exportEqualNamespaceClassESModuleInterop_test.go b/internal/fourslash/tests/gen/exportEqualNamespaceClassESModuleInterop_test.go new file mode 100644 index 0000000000..70828dd486 --- /dev/null +++ b/internal/fourslash/tests/gen/exportEqualNamespaceClassESModuleInterop_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 TestExportEqualNamespaceClassESModuleInterop(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @esModuleInterop: true +// @moduleResolution: node +// @target: es2015 +// @module: esnext +// @Filename: /node_modules/@bar/foo/index.d.ts +export = Foo; +declare class Foo {} +declare namespace Foo {} // class/namespace declaration causes the issue +// @Filename: /node_modules/foo/index.d.ts +import * as Foo from "@bar/foo"; +export = Foo; +// @Filename: /index.ts +import Foo from "foo"; +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/index.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"Foo"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/exportEqualsInterfaceA_test.go b/internal/fourslash/tests/gen/exportEqualsInterfaceA_test.go new file mode 100644 index 0000000000..996c3d9693 --- /dev/null +++ b/internal/fourslash/tests/gen/exportEqualsInterfaceA_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 TestExportEqualsInterfaceA(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: exportEqualsInterface_A.ts +interface A { + p1: number; +} +export = A; +/**/ +var i: I1; +var n: number = i.p1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "import I1 = require(\"exportEqualsInterface_A\");") +} 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..6c418d4bb6 --- /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() + t.Skip() + 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..2000320574 --- /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() + t.Skip() + 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..1e02bacdff --- /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() + t.Skip() + 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..e382ea6594 --- /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() + t.Skip() + 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..eeb9a85761 --- /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() + t.Skip() + 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..dfee6a23bf --- /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() + t.Skip() + 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..f41ebfe43a --- /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() + t.Skip() + 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..0fe615325d --- /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; + millenial: 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..15f486040c --- /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() + t.Skip() + 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..e2fa622891 --- /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() + t.Skip() + 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..a864f48650 --- /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() + t.Skip() + 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_js4_test.go b/internal/fourslash/tests/gen/findAllRefs_importType_js4_test.go new file mode 100644 index 0000000000..aaca8a83db --- /dev/null +++ b/internal/fourslash/tests/gen/findAllRefs_importType_js4_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_js4(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, "") +} 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..08792f35a8 --- /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() + t.Skip() + 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/findReferencesAfterEdit_test.go b/internal/fourslash/tests/gen/findReferencesAfterEdit_test.go new file mode 100644 index 0000000000..d38805586f --- /dev/null +++ b/internal/fourslash/tests/gen/findReferencesAfterEdit_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 TestFindReferencesAfterEdit(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +interface A { + /*1*/foo: string; +} +// @Filename: b.ts +/// +/**/ +function foo(x: A) { + x./*2*/foo +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1", "2") + f.GoToMarker(t, "") + f.Insert(t, "\n") + f.VerifyBaselineFindAllReferences(t, "1", "2") +} 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/genericTypeAliasIntersectionCompletions_test.go b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go new file mode 100644 index 0000000000..b4bd0a0136 --- /dev/null +++ b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_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 TestGenericTypeAliasIntersectionCompletions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` type MixinCtor = new () => A & B & { constructor: MixinCtor }; + function merge(a: { prototype: A }, b: { prototype: B }): MixinCtor { + let merged = function() { } + Object.assign(merged.prototype, a.prototype, b.prototype); + return >merged; + } + + class TreeNode { + value: any; + } + + abstract class LeftSideNode extends TreeNode { + abstract right(): TreeNode; + left(): TreeNode { + return null; + } + } + + abstract class RightSideNode extends TreeNode { + abstract left(): TreeNode; + right(): TreeNode { + return null; + }; + } + + var obj = new (merge(LeftSideNode, RightSideNode))(); + obj./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"right", "left", "value", "constructor"}, + }, + }) +} 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/globalThisCompletion_test.go b/internal/fourslash/tests/gen/globalThisCompletion_test.go new file mode 100644 index 0000000000..d85580f9a8 --- /dev/null +++ b/internal/fourslash/tests/gen/globalThisCompletion_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 TestGlobalThisCompletion(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @target: esnext +// @Filename: test.js +(typeof foo !== "undefined" + ? foo + : {} +)./**/; +// @Filename: someLib.d.ts +declare var foo: typeof globalThis;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", nil) +} diff --git a/internal/fourslash/tests/gen/importTypeCompletions2_test.go b/internal/fourslash/tests/gen/importTypeCompletions2_test.go new file mode 100644 index 0000000000..7992f2ad65 --- /dev/null +++ b/internal/fourslash/tests/gen/importTypeCompletions2_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 TestImportTypeCompletions2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @target: esnext +// @filename: /foo.ts +export const Foo = {}; +// @filename: /bar.ts +[|import type F/**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/bar.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/importValueUsedAsType_test.go b/internal/fourslash/tests/gen/importValueUsedAsType_test.go new file mode 100644 index 0000000000..a77de577a6 --- /dev/null +++ b/internal/fourslash/tests/gen/importValueUsedAsType_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 TestImportValueUsedAsType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +module A { + export var X; + import Z = A.X; + var v: Z; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_test.go b/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_test.go new file mode 100644 index 0000000000..fc55d4ba7a --- /dev/null +++ b/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_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 TestIndexSignatureWithoutAnnotation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface B { + 1: any; +} +interface C { + [s]: any; +} +interface D extends B, C /**/ { +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/indirectJsRequireRename_test.go b/internal/fourslash/tests/gen/indirectJsRequireRename_test.go new file mode 100644 index 0000000000..43f8ccd558 --- /dev/null +++ b/internal/fourslash/tests/gen/indirectJsRequireRename_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 TestIndirectJsRequireRename(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: /bin/serverless.js +require('../lib/classes/Error').log/**/Warning(` + "`" + `CLI triage crashed with: ${error.stack}` + "`" + `); +// @Filename: /lib/plugins/aws/package/compile/events/httpApi/index.js +const { logWarning } = require('../../../../../../classes/Error'); +// @Filename: /lib/classes/Error.js +module.exports.logWarning = message => { };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.VerifyBaselineFindAllReferences(t, "") +} diff --git a/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_test.go b/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_test.go new file mode 100644 index 0000000000..12d656ce7b --- /dev/null +++ b/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_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 TestInsertArgumentBeforeOverloadedConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `alert(/**/100); + +class OverloadedMonster { + constructor(); + constructor(name) { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "'1', ") +} diff --git a/internal/fourslash/tests/gen/insertMethodCallAboveOthers_test.go b/internal/fourslash/tests/gen/insertMethodCallAboveOthers_test.go new file mode 100644 index 0000000000..06c77c0f3b --- /dev/null +++ b/internal/fourslash/tests/gen/insertMethodCallAboveOthers_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 TestInsertMethodCallAboveOthers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +paired.reduce(); +paired.map(() => undefined);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "paired.reduce();") +} diff --git a/internal/fourslash/tests/gen/insertPublicBeforeSetter_test.go b/internal/fourslash/tests/gen/insertPublicBeforeSetter_test.go new file mode 100644 index 0000000000..2248f8e775 --- /dev/null +++ b/internal/fourslash/tests/gen/insertPublicBeforeSetter_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 TestInsertPublicBeforeSetter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /**/set Bar(bar:string) {} +} +var o2 = { set Foo(val:number) { } };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "public ") +} diff --git a/internal/fourslash/tests/gen/insertSecondTryCatchBlock_test.go b/internal/fourslash/tests/gen/insertSecondTryCatchBlock_test.go new file mode 100644 index 0000000000..6ba6bc8d36 --- /dev/null +++ b/internal/fourslash/tests/gen/insertSecondTryCatchBlock_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 TestInsertSecondTryCatchBlock(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try {} catch(e) { } +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "try {} catch(e) { }") +} diff --git a/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_test.go b/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_test.go new file mode 100644 index 0000000000..776aa62b14 --- /dev/null +++ b/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_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 TestInsertVarAfterEmptyTypeParamList(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Dictionary<> { } +var x; +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "var y;\n") +} 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/javaScriptClass4_test.go b/internal/fourslash/tests/gen/javaScriptClass4_test.go new file mode 100644 index 0000000000..b3f93f2d4b --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptClass4_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptClass4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js +class Foo { + constructor() { + /** + * @type {string} + */ + this.baz = null; + } +} +var x = new Foo(); +x/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ".baz.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModules13_test.go b/internal/fourslash/tests/gen/javaScriptModules13_test.go new file mode 100644 index 0000000000..b15e73f9e3 --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModules13_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptModules13(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: myMod.js +if (true) { + module.exports = { a: 10 }; +} +var invisible = true; +// @Filename: isGlobal.js +var y = 10; +// @Filename: consumer.js +var x = require('./myMod'); +/**/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "consumer.js") + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextGlobalsOrKeywords)), Label: "y"}}, + Excludes: []string{"invisible"}, + }, + }) + f.Insert(t, "x.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindField), Label: "a"}}, + }, + }) + f.Insert(t, "a.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModules19_test.go b/internal/fourslash/tests/gen/javaScriptModules19_test.go new file mode 100644 index 0000000000..69f5842ead --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModules19_test.go @@ -0,0 +1,61 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptModules19(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: myMod.js +var x = { a: 10 }; +module.exports = x; +// @Filename: isGlobal.js +var y = 10; +// @Filename: consumer.js +var x = require('./myMod'); +/**/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "consumer.js") + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextGlobalsOrKeywords)), Label: "y"}}, + Excludes: []string{"invisible"}, + }, + }) + f.Insert(t, "x.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindField), Label: "a"}}, + }, + }) + f.Insert(t, "a.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModulesError1_test.go b/internal/fourslash/tests/gen/javaScriptModulesError1_test.go new file mode 100644 index 0000000000..e37b7d41be --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModulesError1_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 TestJavaScriptModulesError1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js +define('mod1', ['a'], /**/function(a, b) { + +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") +} 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..a5a5a3c751 --- /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() + t.Skip() + 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..21d0c0ed94 --- /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() + t.Skip() + 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