Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/core"
"github.com/microsoft/TypeScript/tsc/internal/fourslash"
. "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util"
"github.com/microsoft/TypeScript/tsc/internal/ls/lsutil"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestAutoImportAutomaticJsxRuntimeCrash(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
// @Filename: /project/node_modules/pkg/package.json
{ "name": "pkg", "types": "index.tsx" }

// @Filename: /project/node_modules/pkg/index.tsx
/** @jsxRuntime automatic */
const container = { Widget: { value: <div /> } satisfies {} };
export default container.Widget;

// @Filename: /project/package.json
{ "dependencies": { "pkg": "*" } }

// @Filename: /project/tsconfig.json
{ "compilerOptions": { "jsx": "react-jsx" } }

// @Filename: /project/index.ts
Widg/**/
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.MarkTestAsStradaServer()
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
},
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"Widget"},
},
})
}

func TestAutoImportAutomaticJsxRuntimeProjectReferenceCrash(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
// @Filename: /packages/lib/package.json
{ "name": "lib", "types": "out/index.d.ts" }

// @Filename: /packages/lib/tsconfig.json
{ "compilerOptions": { "composite": true, "jsx": "react-jsx", "outDir": "out" } }

// @Filename: /packages/lib/index.tsx
/** @jsxRuntime automatic */
const container = { Widget: { value: <div /> } satisfies {} };
export default container.Widget;

// @Filename: /packages/app/package.json
{ "dependencies": { "lib": "*" } }

// @Filename: /packages/app/tsconfig.json
{ "references": [{ "path": "../lib" }] }

// @Filename: /packages/app/index.ts
Widg/**/

// @link: /packages/lib -> /packages/app/node_modules/lib
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.MarkTestAsStradaServer()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean f.MarkTestAsStradaServer(), one of the things it does is avoid the usual fourslash behavior of opening every file in the test before running the test (because Strada Server tests didn't have this behavior). We should probably rename it now that we're done with the port.

f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
UserPreferences: &lsutil.UserPreferences{
IncludeCompletionsForModuleExports: core.TSTrue,
IncludeCompletionsForImportStatements: core.TSTrue,
},
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{"Widget"},
},
})
}
2 changes: 1 addition & 1 deletion tsc/internal/ls/autoimport/aliasresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (r *aliasResolver) GetImportHelpersImportSpecifier(path tspath.Path) *ast.N

// GetJSXRuntimeImportSpecifier implements checker.Program.
func (r *aliasResolver) GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node) {
panic("unimplemented")
return "", nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is happening on a real TSX/JSX (even JS) file, won't it be bad that this is not here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda, but not that bad. We only pull on types to get flags that contribute to the little icon in the dropdown list, and it's already an intentional compromise between accuracy and performance. I don't feel bad about stopping the spiraling type resolution here.

}

// GetNearestAncestorDirectoryWithPackageJson implements checker.Program.
Expand Down
Loading