-
Notifications
You must be signed in to change notification settings - Fork 764
Prevent renaming standard library symbols #2232
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
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/prevent-rename-standard-library
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.
+117
−256
Draft
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
febb0d9
Initial plan
Copilot bd58518
Add check to prevent renaming standard library symbols
Copilot eb502d7
Update baseline and apply formatting fixes
Copilot 5a5be05
Improve comments based on code review feedback
Copilot f6734f9
Refactor to match TypeScript implementation using core.Some
Copilot e447950
Remove nil check and handle empty declarations correctly
Copilot 5746f95
Remove empty declarations check - not needed for rename operation
Copilot 9795c2b
Add empty declarations check matching TypeScript semantics
Copilot 9ce1695
Move empty declarations check to getReferencedSymbolsForNode to fix J…
Copilot 864359d
Revert baseline files - JSDoc issue is pre-existing
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
32 changes: 32 additions & 0 deletions
32
internal/fourslash/tests/manual/renameStandardLibrary_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,32 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestRenameStandardLibrary(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = ` | ||
| // Test that standard library symbols cannot be renamed | ||
| /*1*/setTimeout(() => {}, 100); | ||
| /*2*/console.log("test"); | ||
| const arr = [1, 2, 3]; | ||
| arr./*3*/push(4); | ||
| const str = "test"; | ||
| str./*4*/substring(0, 1); | ||
| ` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
|
|
||
| // Try to rename standard library functions - should fail | ||
| markers := []string{"1", "2", "3", "4"} | ||
| for _, marker := range markers { | ||
| f.GoToMarker(t, marker) | ||
| f.VerifyRenameFailed(t, nil /*preferences*/) | ||
| } | ||
| } |
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
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
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.
Do we elsewhere block the declarations that are from a default library file from being renamed?
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.
The way Strada did this was:
This is all of the code that was used to prevent renames, as far as I can tell (beside the ones that are supposed to prevent renaming keywords.
@copilot I don't think what you've written is exactly equivalent; please refactor this to look more like the original code, e.g. not inverted, using
core.Some, etc.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.
Refactored to match the TypeScript implementation exactly. Changed to use
core.Someto check if any declaration is in a library file, and updatedisDefinedInLibraryFileto take a declaration parameter instead of a symbol. Commit: f6734f9