mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Co-authored-by: Oleksandr T <oleksandr.tarasiuk@outlook.com>
This commit is contained in:
parent
5367ae10f5
commit
7b1620bea2
@ -891,7 +891,7 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
|
||||
const unusedImportsFromOldFile = new Set<Symbol>();
|
||||
for (const statement of toMove) {
|
||||
forEachReference(statement, checker, (symbol, isValidTypeOnlyUseSite) => {
|
||||
if (!symbol.declarations) {
|
||||
if (!symbol.declarations || isGlobalType(checker, symbol)) {
|
||||
return;
|
||||
}
|
||||
if (existingTargetLocals.has(skipAlias(symbol, checker))) {
|
||||
@ -952,6 +952,10 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
|
||||
}
|
||||
}
|
||||
|
||||
function isGlobalType(checker: TypeChecker, symbol: Symbol) {
|
||||
return !!checker.resolveName(symbol.name, /*location*/ undefined, SymbolFlags.Type, /*excludeGlobals*/ false);
|
||||
}
|
||||
|
||||
function makeUniqueFilename(proposedFilename: string, extension: string, inDirectory: string, host: LanguageServiceHost): string {
|
||||
let newFilename = proposedFilename;
|
||||
for (let i = 1;; i++) {
|
||||
|
||||
26
tests/cases/fourslash/moveToNewFile_global2.ts
Normal file
26
tests/cases/fourslash/moveToNewFile_global2.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////interface String {
|
||||
//// reverse(): string;
|
||||
////}
|
||||
////
|
||||
////[|String.prototype.reverse = function (): string {
|
||||
//// return this.split("").reverse().join("");
|
||||
////}|]
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/a.ts":
|
||||
`interface String {
|
||||
reverse(): string;
|
||||
}
|
||||
|
||||
`,
|
||||
"/newFile.ts":
|
||||
`String.prototype.reverse = function(): string {
|
||||
return this.split("").reverse().join("");
|
||||
};
|
||||
`,
|
||||
}
|
||||
});
|
||||
25
tests/cases/fourslash/moveToNewFile_global3.ts
Normal file
25
tests/cases/fourslash/moveToNewFile_global3.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////[|// this file extends the string prototype
|
||||
////interface String {
|
||||
//// reverse(): string;
|
||||
////}
|
||||
////String.prototype.reverse = function(): string {
|
||||
//// return this.split("").reverse().join("");
|
||||
////};|]
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/a.ts": "",
|
||||
"/String.ts":
|
||||
`// this file extends the string prototype
|
||||
interface String {
|
||||
reverse(): string;
|
||||
}
|
||||
String.prototype.reverse = function(): string {
|
||||
return this.split("").reverse().join("");
|
||||
};
|
||||
`,
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user