-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Replace endsWith() check with isDefaultLibFile() in getRenameInfo() #1990
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
Conversation
There are a couple of issues with using the current endsWith() function to determine if we should allow a rename for default lib files: 1. XXXX-lib.d.ts would not allow renames even though it should as the preceding characters are not being verified for directory separators 2. There is the potential for false matches as there is currently no check to verify indexOf was successful (index >= 0)
Hi @jramsay, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
I do not think you have this information on the script side. we do not know if lib.d.ts is really a user file, or has been injected into the context by VS. the only one who has this information is VS, and in the genral case, the language service Host. ts.getBaseFileName(ts.normalizePath(fileName)) === getDefaultLibFileName(options); |
88fbdf2
to
93ca5ae
Compare
Thanks for the comments. |
👍 |
if (defaultLibFileName) { | ||
for (var i = 0; i < declarations.length; i++) { | ||
var sourceFile = declarations[i].getSourceFile(); | ||
if (sourceFile && ts.normalizePath(sourceFile.fileName) === ts.normalizePath(defaultLibFileName)) { |
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.
you will need to use getCanonicalFileName here to ensure that case insensitive systems will not have a problem.
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.
good point - done
Replace endsWith() check with canonical normalized path comparison in getRenameInfo()
There are a couple of issues with using the current endsWith() function used to determine if we should allow a rename for default lib files: