Forget block crashes when removing node from ast
See original GitHub issueWhen removing a node (in my case a propertyNode from a class) when inside a forget block, the forget block crashes when trying to clean up (forget) all nodes it doesn’t have to remember. The error thrown is:
Attempted to get information from a node that was removed or forgotten.
I tried remembering the node just before deleting it (with the same remember function, as well as in a new forget block), but it doesn’t seem to help.
ast.forgetNodesCreatedInBlock(remember => {
...
remember(propertyNode); // Doesn't seem to help...
propertyNode.remove();
...
});
gives:
Error: Attempted to get information from a node that was removed or forgotten.
at InvalidOperationError.BaseError [as constructor] (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\errors\BaseError.js:16:28)
at new InvalidOperationError (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\errors\InvalidOperationError.js:17:28)
at PropertyDeclaration.get [as compilerNode] (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\compiler\common\Node.js:87:23)
at PropertyDeclaration.Node.getKind (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\compiler\common\Node.js:138:21)
at ForgetfulNodeCache.forgetNodes (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\factories\ForgetfulNodeCache.js:85:26)
at ForgetfulNodeCache.forgetLastPoint (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\factories\ForgetfulNodeCache.js:51:18)
at CompilerFactory.forgetNodesCreatedInBlock (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\factories\CompilerFactory.js:415:28)
at TsSimpleAst.forgetNodesCreatedInBlock (C:\Users\niekj\projects\projects\apione\node_modules\ts-simple-ast\dist\TsSimpleAst.js:334:37)
It may also be interesting to investigate whether newly created nodes (created as in created with code generation/manipulation, not created from existing code) are forgotten as they should. This may have the same bug, only the other way around. It’s less impactfull as it doesn’t crash, but it may cause a performance issue with bigger projects.
I have currently commented out the forget blocks in the code as a workaround, but that may not be feasable when going to bigger test cases.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
That’s ok! I’m thinking I could capture the stack at the moment it’s removed and then display that to the user in the error message as well. I know these can be hard to figure out sometimes (I’ve done it many times). Opened #751.
@Roaders thanks! 😃 I’m glad it’s been useful for you.