Open Tyriar opened 3 months ago
I have the same problem
I managed to reproduce this error minimally (repo). It occurs on namespace accesses from a module with export * as name from 'mod'
Example:
// mod.ts
export * as Mod from "./mod.js"
export type A = string
// index.ts
import { Mod } from "./mod"
type B = Mod.A
Doing the "Move to file" or "Move to a new file" refactors on type B
produces this error:
Perf 152 [17:42:39.175] 40::getCodeFixes: elapsed time (in milliseconds) 0.6996
Info 153 [17:42:39.175] response:
{"seq":0,"type":"response","command":"getCodeFixes","request_seq":40,"success":true,"body":[{"fixName":"unusedIdentifier","description":"Remove unused declaration for: 'B'","changes":[{"fileName":"c:/dev/demo/ts-move-debug-failure/index.ts","textChanges":[{"start":{"line":3,"offset":1},"end":{"line":3,"offset":16},"newText":""}]}]}]}
Info 154 [17:42:41.133] request:
{
"seq": 41,
"type": "request",
"command": "getEditsForRefactor",
"arguments": {
"file": "c:\\dev\\demo\\ts-move-debug-failure\\index.ts",
"startLine": 3,
"startOffset": 6,
"endLine": 3,
"endOffset": 6,
"refactor": "Move to a new file",
"action": "Move to a new file"
}
}
Err 155 [17:42:41.151] Exception on executing command {
"seq": 41,
"type": "request",
"command": "getEditsForRefactor",
"arguments": {
"file": "c:\\dev\\demo\\ts-move-debug-failure\\index.ts",
"startLine": 3,
"startOffset": 6,
"endLine": 3,
"endOffset": 6,
"refactor": "Move to a new file",
"action": "Move to a new file",
"startPosition": 34,
"endPosition": 34
}
}:
Debug Failure.
Error: Debug Failure.
at Object.addImportFromExportedSymbol (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:154475:32)
at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144415:19
at Map.forEach (<anonymous>)
at addTargetFileImports (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144409:17)
at getNewStatementsAndRemoveFromOldFile (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:143630:3)
at doChange4 (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144615:3)
at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144604:77
at _ChangeTracker.with (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:174571:5)
at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144604:60)
at Object.getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:142721:31)
at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:150173:32)
at IpcIOSession.getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191260:49)
at getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:189429:43)
at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191679:15
at IpcIOSession.executeWithRequestId (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191668:14)
at IpcIOSession.executeCommand (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191677:29)
at IpcIOSession.onMessage (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191725:68)
at process.<anonymous> (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\tsserver.js:525:14)
at process.emit (node:events:514:28)
at emit (node:internal/child_process:951:14)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
File text of c:\dev\demo\ts-move-debug-failure\index.ts:
import { Mod } from "./mod"
type B = Mod.A
Although this might hint at where the problem actually is, it's probably broader than this, because I'm seemingly hitting other cases that don't involve this 🤔
Minimal repro of the original issue:
/// <reference path='fourslash.ts' />
// @allowjs: true
// @Filename: /start.js
//// // @ts-check
////
//// [|const startServer = require('./server.js');
////
//// startServer();|]
// @Filename: /server.js
//// // @ts-check
////
//// function startServer() {
//// }
//// module.exports = startServer;
verify.moveToNewFile({
newFileContents: {
"/start.js":
``,
"/startServer.js":
`<div>a</div>;
`,
}
});
@itsMapleLeaf https://github.com/microsoft/TypeScript/issues/59240#issuecomment-2224079385 should be fixed after https://github.com/microsoft/TypeScript/pull/60333. I think the case you repro-ed is similar to #58897, and is included in my PR.
Repo/file: https://github.com/xtermjs/xterm.js/blob/995ccc72f85dc2f8ab1353dacbfea12202b4a16c/demo/start.js
TypeScript output: