setOrder() bug for ordering class members
See original GitHub issueHey David,
I discovered a bug in setOrder()
when ordering class members.
I’m basically trying to move a class’s constructor below all of the class’s properties. But for some reason, any argument >4 passed to setOrder()
gives me the following error:
Error: Argument Error (order): Range is 0 to 4, but 6 was provided.
However, in my example below, there are clearly there are more than 4 class members. Give it a try:
import Ast from 'ts-simple-ast';
const ast = new Ast();
const sourceFile = ast.createSourceFile( 'test.ts', `
class Something {
constructor() {}
propA = 1;
propB = 2;
propC = 3;
propD = 4;
propE = 5;
propF = 6;
propG = 7;
}
` );
const myClass = sourceFile.getClasses()[ 0 ];
const ctor = myClass.getConstructors()[ 0 ];
ctor.setOrder( 6 ); // <-- Any number greater than 4 here throws an error
console.log( sourceFile.getFullText() );
Why any number greater than 4
specifically? Dunno 😃 I encountered the same error on my Angular migrator too, which also gave an error for any index > 4
, but with completely different source text. Came up with the above minimal reproduction separately.
This is with the latest btw: 6.10.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
C#, How to simply change order of class members
There is no ordering of class members in .NET. Whenever someone iterates over members in a class, they are imposing some order themselves....
Read more >setorder: Fast row reordering of a data.table by reference
setorder (and setorderv ) reorders the rows of a data.table based on the columns (and column order) provided. It reorders the table by...
Read more >ServiceRegistry (Java Platform SE 7 ) - Class
Sets a pairwise ordering between two service provider objects within a given category. Methods inherited from class java.lang.Object · clone, equals, getClass, ...
Read more >Preference - Android Developers
Specify for setOrder(int) if a specific order is not required. ... has been added/removed from this group, or the ordering should be re-evaluated....
Read more >StoreInst Class Reference - LLVM
Sets the ordering constraint and the synchronization scope ID of this store instruction. More... bool, isSimple () const. bool, isUnordered () const ·...
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 FreeTop 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
Top GitHub Comments
Thanks @dsherret, that did the trick!
Would be great if you could add that in the next version! Can’t ask everyone at work to modify their node_modules 😃 hehe
Hahaha, you could add those instructions 😉 lol
Thanks for fixing!