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.

Duplicating lines of code

See original GitHub issue

I am testing out ts-migrate-full on a large project that uses an older version of react. ts-migrate (maybe the explicit-any plugin??) doesn’t seem to be properly replacing code in some plain .js files, as you can see in the code snippet below.

Before

var window = {
    onResetData: function() {
      this.clearNextPush = function() {
        this.resetHistoryResumeData();
        this.setState({ history: [] });
        pubSub.trigger(events.window.CLEAR_HISTORY);
      };
    },
    // more code here
}

After

var window = {
    onResetData: function() {
    (this as any).clearNextPush = function () {
        this.resetHistoryResumeData();
        this.setState({ history: [] });
        pubSub.trigger(events.window.CLEAR_HISTORY);
    };
        (this as any).setState({ history: [] });
        pubSub.trigger(events.window.CLEAR_HISTORY);
      };
    },
    // more code here

}

Expected

var window = {
    onResetData: function() {
    (this as any).clearNextPush = function () {
        this.resetHistoryResumeData();
        (this as any).setState({ history: [] });
        pubSub.trigger(events.window.CLEAR_HISTORY);
      };
    },
    // more code here
}

I am seeing ~1000 errors from tsc but its really just ~200 instances this thought the code base. Manually fixing these bugs isn’t that bad, when compared to all the other work ts-migrate did for me.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Rudegcommented, Aug 26, 2022

@shawngustaw sorry for the delay, done

1reaction
Caliduscommented, Aug 26, 2022

@doncollins Sadly its not simple as just adding Block to the ancestor node check. While it fixes the duplication in the example above, it also adds an extra trailing \n character and causes other tests to fail.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicate line in Visual Studio Code - Stack Overflow
The duplicate can be achieved by CTRL + C and CTRL + V with ...
Read more >
Duplicate line or selection - ReSharper - JetBrains
Press Ctrl+D or choose ReSharper | Edit | Duplicate Text from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing...
Read more >
Duplicate code - Wikipedia
In computer programming, duplicate code is a sequence of source code that occurs more than once, either within a program or across different...
Read more >
Duplicate Code - Refactoring.Guru
Duplication usually occurs when multiple programmers are working on different parts of the same program at the same time. Since they're working on...
Read more >
How to create a duplicate line in VSCode? - W3schools.io
How to create a duplicate line in VSCode? · Windows: Shift + Alt+ Down key and Shift + Alt+ Up key · Linux:...
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