-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Excluded the default library from rename service. #17415
Changes from 4 commits
5b86055
675b6fb
88262db
9dd574b
b03fbaf
1ab67c0
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 |
---|---|---|
|
@@ -670,7 +670,7 @@ namespace ts { | |
if (!hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { | ||
break; | ||
} | ||
// falls through | ||
// falls through | ||
case SyntaxKind.VariableDeclaration: | ||
case SyntaxKind.BindingElement: { | ||
const decl = <VariableDeclaration>node; | ||
|
@@ -682,7 +682,7 @@ namespace ts { | |
visit(decl.initializer); | ||
} | ||
} | ||
// falls through | ||
// falls through | ||
case SyntaxKind.EnumMember: | ||
case SyntaxKind.PropertyDeclaration: | ||
case SyntaxKind.PropertySignature: | ||
|
@@ -729,7 +729,7 @@ namespace ts { | |
|
||
class SourceMapSourceObject implements SourceMapSource { | ||
lineMap: number[]; | ||
constructor (public fileName: string, public text: string, public skipTrivia?: (pos: number) => number) {} | ||
constructor(public fileName: string, public text: string, public skipTrivia?: (pos: number) => number) { } | ||
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. All these white-space changes are interesting. Is it passing the linter? (Was it before?) 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. Yes it is passing linter (before and after). This was done by VS Code formatting, I thought it should be pushed. |
||
|
||
public getLineAndCharacterOfPosition(pos: number): LineAndCharacter { | ||
return ts.getLineAndCharacterOfPosition(this, pos); | ||
|
@@ -1130,14 +1130,14 @@ namespace ts { | |
const newSettings = hostCache.compilationSettings(); | ||
const shouldCreateNewSourceFiles = oldSettings && | ||
(oldSettings.target !== newSettings.target || | ||
oldSettings.module !== newSettings.module || | ||
oldSettings.moduleResolution !== newSettings.moduleResolution || | ||
oldSettings.noResolve !== newSettings.noResolve || | ||
oldSettings.jsx !== newSettings.jsx || | ||
oldSettings.allowJs !== newSettings.allowJs || | ||
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit || | ||
oldSettings.baseUrl !== newSettings.baseUrl || | ||
!equalOwnProperties(oldSettings.paths, newSettings.paths)); | ||
oldSettings.module !== newSettings.module || | ||
oldSettings.moduleResolution !== newSettings.moduleResolution || | ||
oldSettings.noResolve !== newSettings.noResolve || | ||
oldSettings.jsx !== newSettings.jsx || | ||
oldSettings.allowJs !== newSettings.allowJs || | ||
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit || | ||
oldSettings.baseUrl !== newSettings.baseUrl || | ||
!equalOwnProperties(oldSettings.paths, newSettings.paths)); | ||
|
||
// Now create a new compiler | ||
const compilerHost: CompilerHost = { | ||
|
@@ -1365,7 +1365,7 @@ namespace ts { | |
function getCompilerOptionsDiagnostics() { | ||
synchronizeHostData(); | ||
return program.getOptionsDiagnostics(cancellationToken).concat( | ||
program.getGlobalDiagnostics(cancellationToken)); | ||
program.getGlobalDiagnostics(cancellationToken)); | ||
} | ||
|
||
function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { | ||
|
@@ -1510,7 +1510,21 @@ namespace ts { | |
|
||
function getReferences(fileName: string, position: number, options?: FindAllReferences.Options) { | ||
synchronizeHostData(); | ||
return FindAllReferences.findReferencedEntries(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position, options); | ||
|
||
// Exclude default library when renaming as commonly user don't want to change that file. | ||
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. Will this block renaming a symbol declared in a default library? I would think that if a symbol is declared in a default library then we shouldn't allow the rename to proceed at all, rather than renaming it in a user's source files and resulting in possible compile time errors. 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. There's already a feature for that. This will avoid renaming anything on the default library, like comments or strings. |
||
let sourceFiles: SourceFile[] = []; | ||
if (options && options.isForRename) { | ||
for (const sourceFile of program.getSourceFiles()) { | ||
if (!program.isSourceFileDefaultLibrary(sourceFile)) { | ||
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. So previously if you tried to rename something that was defined in the core library (e.g. a JavaScript API such as Array.map, or a DOM API such as window.addEventListener), it would error because you can't rename something in the core library. With this change, will that rename now proceed, but only for all your program files (i.e. leaving you in an error state)? I'm not sure that's a better behavior. 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. That functionality will remain the same. That happens on the function getRenameInfo. |
||
sourceFiles.push(sourceFile); | ||
} | ||
} | ||
} | ||
else { | ||
sourceFiles = program.getSourceFiles(); | ||
} | ||
|
||
return FindAllReferences.findReferencedEntries(program, cancellationToken, sourceFiles, getValidSourceFile(fileName), position, options); | ||
} | ||
|
||
function findReferences(fileName: string, position: number): ReferencedSymbol[] { | ||
|
@@ -2100,7 +2114,7 @@ namespace ts { | |
isLiteralComputedPropertyDeclarationName(node); | ||
} | ||
|
||
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement { | ||
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement { | ||
switch (node.kind) { | ||
case SyntaxKind.JsxAttribute: | ||
case SyntaxKind.JsxSpreadAttribute: | ||
|
@@ -2125,7 +2139,7 @@ namespace ts { | |
if (node.parent.kind === SyntaxKind.ComputedPropertyName) { | ||
return isObjectLiteralElement(node.parent.parent) ? node.parent.parent : undefined; | ||
} | ||
// falls through | ||
// falls through | ||
case SyntaxKind.Identifier: | ||
return isObjectLiteralElement(node.parent) && | ||
(node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression || node.parent.parent.kind === SyntaxKind.JsxAttributes) && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// Tests that tokens found on the default library are not renamed. | ||
// "test" is a comment on the default library. | ||
|
||
// @Filename: file1.ts | ||
//// var [|test|] = "foo"; | ||
//// console.log([|test|]); | ||
|
||
const ranges = test.ranges(); | ||
verify.renameLocations(ranges[0], { findInComments: true, ranges }); |
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.
Why bother with
memoize
and not just haveconst defaultLibraryFileName = host.getDefaultLibraryFileName(options)
?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.
Depending on the options and some logic, the variable might end up not being needed. This was done for lazy evaluation.