Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
/**
* > Strip all code comments, but not these that are
* marked as "ignored" like (`//!` and `/*!`).
* Pass `opts.preserve: false` to remove even them.
*
* **Example**
*
* ```js
* const fs = require('fs')
* const strip = require('acorn-strip-comments')
*
* const str = fs.readFileSync('./index.js', 'utf8')
* const output = strip(str, {})
* // => modified and cleaned string
* ```
*
* @name acornStripComments
* @param {String} `<input>` string from which to get comments
* @param {Object} `opts` optional options, passed to `acorn-extract-comments` and `acorn`
* @param {Boolean} `opts.ast` if `true` the ast is added to the resulting array
* @param {Boolean} `opts.line` if `false` get only block comments, default `true`
* @param {Boolean} `opts.block` if `false` get line comments, default `true`
* @param {Function} `opts.ignore` check function, default check comment starts with `!`
* @param {Boolean} `opts.preserve` if `true` keep comments that are ignored (that pass the `opts.ignore` check)
* @param {Boolean} `opts.locations` if `true` result will include `acorn/esprima` format comment location object
* @param {Number} `opts.ecmaVersion` defaults to `6`, acorn parsing version
* @return {String} modified string
* @api public
*/
exports = module.exports = function stripAllComments (input, opts) {
opts = extend({line: true, block: true, preserve: true}, opts)
return acornStripComments(input, opts)
}
I think this should work as do it currently by using @option or @property, which btw both of them do some strange things with identation.
For example, doing it currently and correctly like that
/**
* > Strip all code comments, but not these that are
* marked as "ignored" like (`//!` and `/*!`).
* Pass `opts.preserve: false` to remove even them.
*
* **Example**
*
* ```js
* const fs = require('fs')
* const strip = require('acorn-strip-comments')
*
* const str = fs.readFileSync('./index.js', 'utf8')
* const output = strip(str, {})
* // => modified and cleaned string
* ```
*
* @name acornStripComments
* @param {String} `<input>` string from which to get comments
* @param {Object} `opts` optional options, passed to `acorn-extract-comments` and `acorn`
* @option {Boolean} [opts] `ast` if `true` the ast is added to the resulting array
* @option {Boolean} [opts] `line` if `false` get only block comments, default `true`
* @option {Boolean} [opts] `block` if `false` get line comments, default `true`
* @option {Function} [opts] `ignore` check function, default check comment starts with `!`
* @option {Boolean} [opts] `preserve` if `true` keep comments that are ignored (that pass the `opts.ignore` check)
* @option {Boolean} [opts] `locations` if `true` result will include `acorn/esprima` format comment location object
* @option {Number} [opts] `ecmaVersion` defaults to `6`, acorn parsing version
* @return {String} modified string
* @api public
*/
exports = module.exports = function stripAllComments (input, opts) {
opts = extend({line: true, block: true, preserve: true}, opts)
return acornStripComments(input, opts)
}
adds options as sublist but with huge indent and adds one line more above the returns which is with same indent as options sublist
### [acornStripComments](index.js#L43)
> Strip all code comments, but not these that are marked as "ignored" like (`//!` and `/*!`). Pass `opts.preserve: false` to remove even them.
**Params**
* `<input>` **{String}**: string from which to get comments
* `opts` **{Object}**: optional options, passed to `acorn-extract-comments` and `acorn`
- `ast` **{Boolean}**: if `true` the ast is added to the resulting array
- `line` **{Boolean}**: if `false` get only block comments, default `true`
- `block` **{Boolean}**: if `false` get line comments, default `true`
- `ignore` **{Function}**: check function, default check comment starts with `!`
- `preserve` **{Boolean}**: if `true` keep comments that are ignored (that pass the `opts.ignore` check)
- `locations` **{Boolean}**: if `true` result will include `acorn/esprima` format comment location object
- `ecmaVersion` **{Number}**: defaults to `6`, acorn parsing version
* `returns` **{String}**: modified string
consider following example
I think this should work as do it currently by using
@option
or@property
, which btw both of them do some strange things with identation.For example, doing it currently and correctly like that
adds options as sublist but with huge indent and adds one line more above the
returns
which is with same indent as options sublist