GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add code fix to remove unreachable code · Pull Request #24028 · microsoft/TypeScript ConversationMentioned in #24026
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
ghost
force-pushed
the
codeFixUnreachableCode
branch
from
7b9ac54 to
539a43d
Compare
ghost
force-pushed
the
codeFixUnreachableCode
branch
from
539a43d to
88b7948
Compare
Contributor
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 the statement was not in a block, that will leave the the ifStatement syntactically incorrect.. e.g. if (false) console.log(); else console.log();
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
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. you want to return all statemetns from this one untill the end of the block, e.g.: function f() { return 0; // both should be removed, error is only on the first. var x = 0; console.log(x); }
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Mohamed Hegazy (mhegazy)
approved these changes
Contributor
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. You probably also want to preserve type alias declarations, interfaces, const enums, type only namespaces, var statements, ...
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| newFileContent: | ||
| ` | ||
| // No good way to delete just the 'if' part | ||
| if (false) { } else b; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In a perfect world, the output would be b;?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| case SyntaxKind.IfStatement: | ||
| if ((container as IfStatement).elseStatement) { | ||
| if (isBlock(statement.parent)) { | ||
| changes.deleteNodeRange(sourceFile, first(statement.parent.statements), last(statement.parent.statements)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to eliminate the whole else-clause?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| function shouldRemove(s: Statement): boolean { | ||
| // Don't remove statements that can validly be used before they appear. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something - why would it be reported as unused if it's used above?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| split(sliceAfter(statement.parent.statements, statement), shouldRemove, (start, end) => changes.deleteNodeRange(sourceFile, start, end)); | ||
| } | ||
| else { | ||
| changes.deleteNode(sourceFile, statement); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will a switch case ever be reported as unused? Does that need special handling? What about a catch block?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.