diff --git a/README.html b/README.html
index 5f37ac0f..4b0afd17 100644
--- a/README.html
+++ b/README.html
@@ -448,6 +448,11 @@
1.4 Usage
comment tokens in the generated code (assumed to be copyright information
etc.). If you pass this it will discard it.
+
+-nl
or --no-licenses
— by default, uglifyjs
will keep the text
+ marked /*! */ in the generated code (assumed to be license information
+ etc.). If you pass this it will discard it.
+
-o filename
or --output filename
— put the result in filename
. If
this isn't given, the result goes to standard output (or see next one).
diff --git a/README.org b/README.org
index d36b6b26..05b7188d 100644
--- a/README.org
+++ b/README.org
@@ -224,6 +224,10 @@ Supported options:
comment tokens in the generated code (assumed to be copyright information
etc.). If you pass this it will discard it.
+- =-nl= or =--no-licenses= --- by default, =uglifyjs= will keep the text
+ marked /*! */ in the generated code (assumed to be license information
+ etc.). If you pass this it will discard it.
+
- =-o filename= or =--output filename= --- put the result in =filename=. If
this isn't given, the result goes to standard output (or see next one).
diff --git a/bin/uglifyjs b/bin/uglifyjs
index df5201da..c13e3566 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -3,7 +3,7 @@
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
var fs = require("fs");
-var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
+var uglify = require("../uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
consolidator = uglify.consolidator,
jsp = uglify.parser,
pro = uglify.uglify;
@@ -32,7 +32,8 @@ var options = {
indent_start: 0,
quote_keys: false,
space_colon: false,
- inline_script: false
+ inline_script: false,
+ licenses: true
},
make: false,
output: true // stdout
@@ -86,6 +87,10 @@ out: while (args.length > 0) {
case "-nc":
options.show_copyright = false;
break;
+ case "--no-licenses":
+ case "-nl":
+ options.codegen_options.licenses = false;
+ break;
case "-o":
case "--output":
options.output = args.shift();
diff --git a/lib/parse-js.js b/lib/parse-js.js
index dccd6238..8686bd52 100644
--- a/lib/parse-js.js
+++ b/lib/parse-js.js
@@ -466,7 +466,6 @@ function tokenizer($TEXT) {
};
function read_multiline_comment() {
- next();
return with_eof_error("Unterminated multiline comment", function(){
var i = find("*/", true),
text = S.text.substring(S.pos, i);
@@ -546,6 +545,18 @@ function tokenizer($TEXT) {
return token("operator", grow(prefix || next()));
};
+ function read_license() {
+ return with_eof_error("Unterminated license statement", function(){
+ var i = find("*/", true),
+ text = S.text.substring(S.pos, i);
+ for (var j=0; j= 0;
+ return token("license", text);
+ });
+ };
+
function handle_slash() {
next();
var regex_allowed = S.regex_allowed;
@@ -555,8 +566,15 @@ function tokenizer($TEXT) {
S.regex_allowed = regex_allowed;
return next_token();
case "*":
- S.comments_before.push(read_multiline_comment());
+ next();
S.regex_allowed = regex_allowed;
+ if (peek()=='!') {
+ // A license statment starts /*!
+ next();
+ return read_license();
+ } else {
+ S.comments_before.push(read_multiline_comment());
+ }
return next_token();
}
return S.regex_allowed ? read_regexp("") : read_operator("/");
@@ -682,7 +700,6 @@ function NodeWithToken(str, start, end) {
NodeWithToken.prototype.toString = function() { return this.name; };
function parse($TEXT, exigent_mode, embed_tokens) {
-
var S = {
input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT,
token : null,
@@ -755,7 +772,12 @@ function parse($TEXT, exigent_mode, embed_tokens) {
};
function as() {
- return slice(arguments);
+ var arr = slice(arguments);
+ if (S.token.comments_before && S.token.comments_before.length) {
+ arr.comments_before = S.token.comments_before;
+ }
+ if (S.token.line) arr.line = S.token.line;
+ return arr;
};
function parenthesised() {
@@ -792,6 +814,9 @@ function parse($TEXT, exigent_mode, embed_tokens) {
case "atom":
return simple_statement();
+ case "license":
+ return as("license", prog1(S.token.value, next));
+
case "name":
return is_token(peek(), "punc", ":")
? labeled_statement(prog1(S.token.value, next, next))
@@ -886,6 +911,10 @@ function parse($TEXT, exigent_mode, embed_tokens) {
return as("label", label, stat);
};
+ function license() {
+ return as("license", prog1(expression));
+ };
+
function simple_statement() {
return as("stat", prog1(expression, semicolon));
};
diff --git a/lib/process.js b/lib/process.js
index da5553c7..352aabb8 100644
--- a/lib/process.js
+++ b/lib/process.js
@@ -202,6 +202,9 @@ function ast_walker() {
},
"atom": function(name) {
return [ this[0], name ];
+ },
+ "license": function(name) {
+ return [ this[0], name ];
}
};
@@ -1418,7 +1421,8 @@ function gen_code(ast, options) {
space_colon : false,
beautify : false,
ascii_only : false,
- inline_script: false
+ inline_script: false,
+ licenses: true
});
var beautify = !!options.beautify;
var indentation = 0,
@@ -1547,6 +1551,12 @@ function gen_code(ast, options) {
"string": encode_string,
"num": make_num,
"name": make_name,
+ "license": function(text){
+ if (!options.licenses) {
+ return '';
+ }
+ return "/*!" + text + '*/';
+ },
"debugger": function(){ return "debugger" },
"toplevel": function(statements) {
return make_block_statements(statements)
diff --git a/test/testparser.js b/test/testparser.js
index 02c19a9c..c42e4b19 100755
--- a/test/testparser.js
+++ b/test/testparser.js
@@ -23,6 +23,7 @@ function ParserTestSuite(callback){
["var abc = 5;", "Regular variable statement with assignment"],
["/* */;", "Multiline comment"],
['/** **/;', 'Double star multiline comment'],
+ ["/*! */;", "License statement"],
["var f = function(){;};", "Function expression in var assignment"],
['hi; // moo\n;', 'single line comment'],
['var varwithfunction;', 'Dont match keywords as substrings'], // difference between `var withsomevar` and `"str"` (local search and lits)
diff --git a/test/unit/compress/expected/license.js b/test/unit/compress/expected/license.js
new file mode 100644
index 00000000..05c523dc
--- /dev/null
+++ b/test/unit/compress/expected/license.js
@@ -0,0 +1,3 @@
+/*! License 1 *//*! Multiline
+ License 2
+*/var a=1;/*! License 3 */var b=1
\ No newline at end of file
diff --git a/test/unit/compress/test/license.js b/test/unit/compress/test/license.js
new file mode 100644
index 00000000..38d79bcd
--- /dev/null
+++ b/test/unit/compress/test/license.js
@@ -0,0 +1,7 @@
+/*! License 1 */
+/*! Multiline
+ License 2
+*/
+var a=1;
+/*! License 3 */
+var b=1;
\ No newline at end of file