From 675b6fb90ce3b8e659a6acc4f161a64cb31b111a Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Tue, 25 Jul 2017 16:29:08 -0700 Subject: [PATCH] Fixed failing tests and lint. Added unit tests. --- src/services/services.ts | 9 +++++---- tests/cases/fourslash/renameDefaultLibDontWork.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/renameDefaultLibDontWork.ts diff --git a/src/services/services.ts b/src/services/services.ts index 998a5d3689..2a1b0bf4eb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1511,15 +1511,16 @@ namespace ts { function getReferences(fileName: string, position: number, options?: FindAllReferences.Options) { synchronizeHostData(); - //Exclude default library when renaming as commonly user don't want to change that file. + // Exclude default library when renaming as commonly user don't want to change that file. let sourceFiles: SourceFile[] = []; - if (options.isForRename) { - for (let sourceFile of program.getSourceFiles()) { + if (options && options.isForRename) { + for (const sourceFile of program.getSourceFiles()) { if (!program.isSourceFileDefaultLibrary(sourceFile)) { sourceFiles.push(sourceFile); } } - } else { + } + else { sourceFiles = program.getSourceFiles(); } diff --git a/tests/cases/fourslash/renameDefaultLibDontWork.ts b/tests/cases/fourslash/renameDefaultLibDontWork.ts new file mode 100644 index 0000000000..5d2cfb43eb --- /dev/null +++ b/tests/cases/fourslash/renameDefaultLibDontWork.ts @@ -0,0 +1,11 @@ +/// + +// 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 }); \ No newline at end of file