-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Prevent auto-import crash with automatic JSX runtime #64417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
648066b
0ab1731
2c7a5a2
5c3daaf
a785796
1995e1d
95d6238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() | ||
| 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"}, | ||
| }, | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
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.