[Pkg-javascript-commits] [uglifyjs] 35/49: Don't filter shebangs when using the 'some' comment filter
Jonas Smedegaard
dr at jones.dk
Fri Dec 9 11:43:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 8d74f3437352e22b3fd18ce602a4378170ec6598
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date: Sun Oct 16 20:57:28 2016 +0200
Don't filter shebangs when using the 'some' comment filter
Also clarify documentation a bit more about using regexp as filter
---
README.md | 9 +++++----
bin/uglifyjs | 2 +-
lib/output.js | 1 +
test/mocha/comment-filter.js | 5 +++++
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 87d828a..789219d 100644
--- a/README.md
+++ b/README.md
@@ -98,8 +98,8 @@ The available options are:
"@preserve". You can optionally pass one of the
following arguments to this flag:
- "all" to keep all comments
- - a valid JS regexp (needs to start with a
- slash) to keep only comments that match.
+ - a valid JS RegExp like `/foo/` or `/^!/` to
+ keep only matching comments.
Note that currently not *all* comments can be
kept when compression is on, because of dead
code removal or cascading statements into
@@ -855,10 +855,11 @@ which we care about here are `source_map` and `comments`.
#### Keeping comments in the output
In order to keep certain comments in the output you need to pass the
-`comments` option. Pass a RegExp, boolean or a function. Stringified options
+`comments` option. Pass a RegExp (as string starting and closing with `/`
+or pass a RegExp object), a boolean or a function. Stringified options
`all` and `some` can be passed too, where `some` behaves like it's cli
equivalent `--comments` without passing a value. If you pass a RegExp,
-only those comments whose body matches the regexp will be kept. Note that body
+only those comments whose body matches the RegExp will be kept. Note that body
means without the initial `//` or `/*`. If you pass a function, it will be
called for every comment in the tree and will receive two arguments: the
node that the comment is attached to, and the comment token itself.
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 7643896..ce2e941 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -47,7 +47,7 @@ Use -c with no argument to use the default compression options.")
By default this works like Google Closure, keeping JSDoc-style comments that contain \"@license\" or \"@preserve\". \
You can optionally pass one of the following arguments to this flag:\n\
- \"all\" to keep all comments\n\
-- a valid JS regexp (needs to start with a slash) to keep only comments that match.\n\
+- a valid JS RegExp like `/foo/`or `/^!/` to keep only matching comments.\n\
\
Note that currently not *all* comments can be kept when compression is on, \
because of dead code removal or cascading statements into sequences.")
diff --git a/lib/output.js b/lib/output.js
index 014dac4..63a78c6 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -101,6 +101,7 @@ function OutputStream(options) {
// multiline comment
return /@preserve|@license|@cc_on/i.test(text);
}
+ return type == "comment5";
}
}
else if (options.comments){ // NOTE includes "all" option
diff --git a/test/mocha/comment-filter.js b/test/mocha/comment-filter.js
index 4330d1e..7916275 100644
--- a/test/mocha/comment-filter.js
+++ b/test/mocha/comment-filter.js
@@ -57,4 +57,9 @@ describe("comment filters", function() {
assert.strictEqual(ast.print_to_string({comments: f}), "#!Random comment\n//test1\n/*test2*/\n");
});
+
+ it("Should never be able to filter comment5 when using 'some' as filter", function() {
+ var ast = UglifyJS.parse("#!foo\n//foo\n/*@preserve*/\n/* please hide me */");
+ assert.strictEqual(ast.print_to_string({comments: "some"}), "#!foo\n/*@preserve*/\n");
+ });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list