JavaScript strip comments from javascript files in bulk strip comments from html,strip comments from c code,strip

I'm doing some analysis on a large base, mostly javascript (it's actually mostly Siebel eScript, but that's more or less the same thing, grammatically)

Over the years, bad programmers have been in and commented large sections of code, often the whole content of a function and left it there. I want to go across the code base looking for examples like this, so that I can direct developers to go back and clean some of this mess up. I have >10,000 files so I'd like a bash script to do this for me.

What I'd ultimately like is something that goes through text files in a linux fs and outputs, per file, the character counts of code vs. comment.

What I've tried:

sed - a few questions on here lead to regular expressions that find // lines and /* */ pairs and remove the comments associated. I've tried a few snippets but they seems to fail (not return) on enough of my code, or strip out non-comments - so I think regex is not the way to go.

yui-compressor - I tried this but I couldn't find how to make it just strip comments. Minifying meant my wc -c results were too skewed

The ideal answer to this question right now would be the one that tells me what command line parser to use to process my javascript files to just remove comments. I can do the rest myself, but it feels like that is the part that currently eludes me.

Answer:1

Given that you are unclear about the OS, it'll be hard to guess what command line parser you have. (wc is available under Linux and with cygwin, under windows).

I don't think it is a "command line" that does the trick, you need a tool that knows Javascript, Given that your problem is one of retaining valid javascript lexemes, and throwing away just the comments, it would seem like a regexp would be possible. Its probably pretty hard to write, since it has to be the disjunction of all the regexps for every lexeme in the language. People use lexer generators to compute that disjunction; you probably can't do it by hand. (Yes, I've written production JavaScript lexers).

The easiest way to get this effect is get your hands on a full Javascript lexer/parser.

Our Javascript Formatter contains such a lexer/parser; it job is to reformat your code. One of its command line options is to strip comments. You can configure it to process lots of files in one step using a project file.

That would probably work for you, based on Seibel's assertion that escript is ECMAScript 4 compliant.

Answer:2

I need to find a very performant way to find out if a custom element or any of its parent elements has display: none; First approach: checkVisible() { let parentNodes = []; let el = this; ...

I need to find a very performant way to find out if a custom element or any of its parent elements has display: none; First approach: checkVisible() { let parentNodes = []; let el = this; ...

How can I share pdf file link or image link which will open in react native mobile app web browser. I have added a share button but when the user clicks on it, it opens where to share menu options ...

How can I share pdf file link or image link which will open in react native mobile app web browser. I have added a share button but when the user clicks on it, it opens where to share menu options ...

<div id="parent"> <div id="child1"> <div id="child2"> <div id="child3"> <div id="child4"> </div> </...

<div id="parent"> <div id="child1"> <div id="child2"> <div id="child3"> <div id="child4"> </div> </...

  1. javascript parent elements
  2. javascript get parent elements
  3. javascript traverse parent elements
  4. javascript multiple parent elements
  5. javascript all parent elements
  6. javascript remove parent elements
  7. javascript iframe parent elements
  8. javascript get all parent elements
  9. javascript find all parent elements
  10. javascript find elements parent

As an example, let's say I've a component that can take in props like this: const testComponent = (props: {isBold: boolean}) => { if(props.isBold) return <strong><div>hello</...

As an example, let's say I've a component that can take in props like this: const testComponent = (props: {isBold: boolean}) => { if(props.isBold) return <strong><div>hello</...