question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setOrder() bug for ordering class members

See original GitHub issue

Hey 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gregjacobscommented, Feb 8, 2018

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

0reactions
gregjacobscommented, Feb 9, 2018

Hahaha, you could add those instructions 😉 lol

Thanks for fixing!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found