Typescript: feature request - remove debugger; statements using tsc

Created on 10 Apr 2017  ·  10Comments  ·  Source: microsoft/TypeScript

Looking at the compiler options:

https://www.typescriptlang.org/docs/handbook/compiler-options.html

it does not look like removing

debugger;

statements in a codebase is possible when transpiling. This would be a very useful feature, and since TS / tsc are not tightly coupled with Babel, then I think tsc users could use this feature.

thanks

Out of Scope Suggestion

Most helpful comment

This seems like a good fit for a custom transformer. You could drop whatever syntax pieces you wanted with it. Example: https://github.com/alexeagle/ts_plugin_prototype/blob/master/eraseDecoratorsTransform.ts

All 10 comments

If tsc removed debugger statements, then they would not be very useful.

Consider using the _tslint_ rule

"no-debugger": true

@aluanhaddad huh? debugger; statements are placed in the code by the developer and sometimes the developer forgets to remove them before releasing code.

Might I say the same thing about /* comments */ ? Stripping comments from transpiled code makes comments useless also... but we still do it. Lol. Idk what to say.

You have won an award in my mind today for strangest response.

But you're right, there are other tools that might be able to remove debugger; statements or warn of their existence.

As pointed out, you sometimes do want debugger statements (otherwise why would they be there). Sometimes wanting them and sometimes not implies two build configurations. So at that point that you have two build configurations, you may as well make one of them tell you when you have a debugger statement that you should get rid of, rather than check them in. I mean, who wants to sync up their code changes only to find some random coworker's debugger statements breaking in the debugger?

@RyanCavanaugh that is true, I actually want to keep one particular debugger; statement in my codebase and I was wondering how I could accomplish that while using a debugger; stripper.

I don't think this is out of scope for TS/tsc because many people using TSC don't want to use Babel, etc.

Imagine this:

debugger;

vs.

debugger; // (tsc-save)

tsc could do some intelligent work to keep the debugger; statement if a comment postcedes the debugger; statement and contains "(tsc-save)" or whatever

just an idea

But if you lint code, and you should lint your code, you can use

rules: {
  "no-debugger": true
}

Then for the case you mentioned where you actually do want the statement, you can write

function notCalledInProduction() {
  ...
  /* tslint:disable-next-line */
  debugger;
  ...
}

@aluanhaddad I don't quite follow your last post, trying to understand it, but I think you misunderstand my request - as you know linters do not do the work of automatically removing extra debugger; statements. I don't use linters, personally. But tsc _is capable_ of removing unwanted debugger; statements during transpilation, hence the feature request.

@ORESoftware

I don't use linters, personally.

🙀 🙀 🙀

@aluanhaddad I know, I know. Here's a plug for node-check-fast though:

https://github.com/ORESoftware/node-check-fast

the most I do is node -c on all my files, this hopefully prevents the odd git merge fiasco.

This seems like a good fit for a custom transformer. You could drop whatever syntax pieces you wanted with it. Example: https://github.com/alexeagle/ts_plugin_prototype/blob/master/eraseDecoratorsTransform.ts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zlatkovsky picture Zlatkovsky  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

wmaurer picture wmaurer  ·  3Comments