-
Notifications
You must be signed in to change notification settings - Fork 962
Fix external helper crash after module-status updates #3994
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
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/fix-check-external-emit-helpers-again
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2a5f01a
Initial plan
Copilot 083640c
Fix helper checks after module update
Copilot d0a1ad8
Strengthen helper update regression
Copilot 7f7ac86
Clean up helper regression test
Copilot 4f19c00
Move helper regression to fourslash
Copilot 7a1766c
Clarify fourslash helper edit
Copilot f732c93
Document helper resolution assertion
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
internal/fourslash/tests/importHelpersAfterScriptBecomesDecoratedModule_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestImportHelpersAfterScriptBecomesDecoratedModule(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
|
|
||
| const content = `// @Filename: /tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2015", | ||
| "module": "commonjs", | ||
| "experimentalDecorators": true, | ||
| "importHelpers": true | ||
| }, | ||
| "files": ["foo.ts"] | ||
| } | ||
|
|
||
| // @Filename: /foo.ts | ||
| declare function dec(value: Function): void; | ||
| /*insert*/class C {} | ||
|
|
||
| // @Filename: /node_modules/tslib/package.json | ||
| { "name": "tslib", "typings": "tslib.d.ts" } | ||
|
|
||
| // @Filename: /node_modules/tslib/tslib.d.ts | ||
| export declare function __decorate(...args: any[]): any; | ||
|
|
||
| // @Filename: /node_modules/tslib/tslib.js | ||
| exports.__decorate = function () {}; | ||
| ` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
|
|
||
| f.GoToFile(t, "/foo.ts") | ||
| f.VerifyNumberOfErrorsInCurrentFile(t, 0) | ||
| f.Replace(t, f.MarkerByName(t, "insert").Position, 0, `@dec | ||
| export `) | ||
| // The second diagnostics request forces external helper resolution after the edit. | ||
| f.VerifyNumberOfErrorsInCurrentFile(t, 0) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't we need to check that they're equal in some way?
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't think so - my understanding is that these are used to determine if the program is sufficiently structurally the same to avoid rebuilding a full program - not that the files themselves are "equal" before/after. Below, we check that the rest of the structure is equal (e.g. same imports, global modifications, etc.)
From
program.go's perspective, the external module indicator probably should not be used to determine anything about the file other than "is this a module, or is this a global?"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.
Actually, I'm not sure I understand why this fix works at all. These are actually a pure function of the file contents + external module indicator options (which is just the file path+reads), which are part of the cache key for files, so when would these change and us not invalidate, or, why would reusing them ever be wrong
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not sure which portion you're thinking of, but basically here's what's happening.
First off, every
ProgramincludesprocessedFileswhich contains a map offilePath -> synthesizedStringLiteralsToBeUsedAsImportSpecifiers. This seems to me to be calculated at parse-time, but this state is located on the program, not on the file. So as far as I understand, the parse cache wouldn't really come into play here.Now when a file change comes in, the idea is we try to reuse a lot of the program state for the new
Program.UpdateProgramdoes this viacanReplaceFileInProgram. The checks here ensure that we cannot reuse program state related to locating tslib for ascript -> moduletransition.