fixMissingImports breaks when adding to empty named imports
See original GitHub issueI’m not sure exactly what happened here, but I had:
import { } from "../jsx";
And that caused this:
Error: Cannot get the next when at the end of the iterator.
-- Details --
Path: V:/ts-morph/src/structures/utils/forEachStructureChild.ts
Text: "...dDeclarationStructure, ParameteredNodeStructure, TypeElementMemberedNodeStructure } from \"../base\";\r\nimport { JsxElementStructure, JsxSelfClosingElementStructure, JsxAttributedNodeStructure }{ } from \"../jsx\";\r\nimport { VariableStatementStructure } from \"../statement\";\r\n\r\n// todo: Code generate this...\r\n\r\nexp..."
Stack: Error: Cannot get the next when at the end of the iterator.
at AdvancedIterator.next (V:\ts-morph\node_modules\ts-morph\dist\utils\AdvancedIterator.js:33:19)
at RangeHandler.handleNode (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\RangeHandler.js:38:78)
at NodeHandlerHelper.handleForValues (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\NodeHandlerHelper.js:12:21)
at RangeHandler.rangeHandlerReplace (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\RangeHandler.js:48:21)
at RangeHandler.handleNode (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\RangeHandler.js:31:18)
at NodeHandlerHelper.handleForValues (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\NodeHandlerHelper.js:12:21)
at RangeHandler.rangeHandlerReplace (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\RangeHandler.js:48:21)
at RangeHandler.handleNode (V:\ts-morph\node_modules\ts-morph\dist\manipulation\nodeHandlers\RangeHandler.js:31:18)
at Object.doManipulation (V:\ts-morph\node_modules\ts-morph\dist\manipulation\manipulations\doManipulation.js:9:21)
at Object.insertIntoTextRange (V:\ts-morph\node_modules\ts-morph\dist\manipulation\manipulations\insertion.js:34:22)
at Object.doManipulation (V:\ts-morph\node_modules\ts-morph\dist\manipulation\manipulations\doManipulation.js:12:15)
at Object.insertIntoTextRange (V:\ts-morph\node_modules\ts-morph\dist\manipulation\manipulations\insertion.js:34:22)
at applyTextChanges (V:\ts-morph\node_modules\ts-morph\dist\compiler\ast\module\SourceFile.js:656:32)
at SourceFile.fixMissingImports (V:\ts-morph\node_modules\ts-morph\dist\compiler\ast\module\SourceFile.js:636:13)
at Object.createForEachStructureChild (V:\ts-morph\scripts\generation\createForEachStructureChild.ts:29:31)
at Object.<anonymous> (V:\ts-morph\scripts\generation\main.ts:46:9)
at Generator.next (<anonymous>)
at V:\ts-morph\scripts\generation\main.ts:7:71
at new Promise (<anonymous>)
at __awaiter (V:\ts-morph\scripts\generation\main.ts:3:12)
Kind of looks like that might be a bug in the compiler though.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Goland inconsistently formats imports when they are grouped ...
However goland mixes all the imports in one group once it tries to add a new import. Also it is confused with empty...
Read more >Issues closed in the 1.0 development cycle
PR #4132: Fixed name error bug in function safe_unicode in module py3compat. ... PR #3782: add Importing Notebooks example.
Read more >IPython Documentation - Read the Docs
The notebook has added separate Edit and Command modes, allowing easier keyboard ... PR #2373: fix missing imports in core.interactiveshell.
Read more >Upgrading Unity Container (Changelog)
Then, use Resharper to fix missing imports in the entire solution in one action. Upgrading to Unity.Abstractions 4.0.0.0. A few breaking changes have...
Read more >Imports - ts-morph
Imports · Add/Insert · Remove · Module specifier · Default import · Namespace import · Named imports.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That seems to have been the case for me at least. It would be interesting to hear from others if this fixes their issues as well.
So, in this case we’re using the comment at the top of the file as a way of noting that we’re basing our implementation on someone else’s. Maybe you’d like to give extra context about a module via a code comment. There could be other use cases where a comment at the top of the file is desirable, like, maybe for licensing purposes, or for linter disabling at the file level, which is usually done with an enriched comment. The fact is, I don’t know if it’s fair to assume that the user wouldn’t want to keep that comment at the top of the file.
Agreed.
I get the same error when adding JSDoc to an interface declaration and then call
fixMissingImports()
on source file. Without JSDoc everything is working fine.Any idea?