Add --screw-ie option
For now the implication is that UglifyJS will not leak a function expression's name in the surrounding scope (IE < 9 does that). (ref. mishoo/UglifyJS#485)
This commit is contained in:
@@ -21,6 +21,7 @@ mangling you need to use `-c` and `-m`.\
|
|||||||
.describe("source-map-root", "The path to the original source to be included in the source map.")
|
.describe("source-map-root", "The path to the original source to be included in the source map.")
|
||||||
.describe("source-map-url", "The path to the source map to be added in //@ sourceMappingURL. Defaults to the value passed with --source-map.")
|
.describe("source-map-url", "The path to the source map to be added in //@ sourceMappingURL. Defaults to the value passed with --source-map.")
|
||||||
.describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.")
|
.describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.")
|
||||||
|
.describe("screw-ie", "Pass this flag if you don't care about full compliance with Internet Explorer quirks (by default UglifyJS will try to be IE-proof).")
|
||||||
.describe("p", "Skip prefix for original filenames that appear in source maps. \
|
.describe("p", "Skip prefix for original filenames that appear in source maps. \
|
||||||
For example -p 3 will drop 3 directories from file names and ensure they are relative paths.")
|
For example -p 3 will drop 3 directories from file names and ensure they are relative paths.")
|
||||||
.describe("o", "Output file (default STDOUT).")
|
.describe("o", "Output file (default STDOUT).")
|
||||||
@@ -71,6 +72,7 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
.string("d")
|
.string("d")
|
||||||
.string("comments")
|
.string("comments")
|
||||||
.string("wrap")
|
.string("wrap")
|
||||||
|
.boolean("screw-ie")
|
||||||
.boolean("export-all")
|
.boolean("export-all")
|
||||||
.boolean("self")
|
.boolean("self")
|
||||||
.boolean("v")
|
.boolean("v")
|
||||||
@@ -246,7 +248,7 @@ var SCOPE_IS_NEEDED = COMPRESS || MANGLE || ARGS.lint;
|
|||||||
|
|
||||||
if (SCOPE_IS_NEEDED) {
|
if (SCOPE_IS_NEEDED) {
|
||||||
time_it("scope", function(){
|
time_it("scope", function(){
|
||||||
TOPLEVEL.figure_out_scope();
|
TOPLEVEL.figure_out_scope({ screw_ie: ARGS.screw_ie });
|
||||||
if (ARGS.lint) {
|
if (ARGS.lint) {
|
||||||
TOPLEVEL.scope_warnings();
|
TOPLEVEL.scope_warnings();
|
||||||
}
|
}
|
||||||
@@ -261,7 +263,7 @@ if (COMPRESS) {
|
|||||||
|
|
||||||
if (SCOPE_IS_NEEDED) {
|
if (SCOPE_IS_NEEDED) {
|
||||||
time_it("scope", function(){
|
time_it("scope", function(){
|
||||||
TOPLEVEL.figure_out_scope();
|
TOPLEVEL.figure_out_scope({ screw_ie: ARGS.screw_ie });
|
||||||
if (MANGLE) {
|
if (MANGLE) {
|
||||||
TOPLEVEL.compute_char_frequency(MANGLE);
|
TOPLEVEL.compute_char_frequency(MANGLE);
|
||||||
}
|
}
|
||||||
|
|||||||
21
lib/scope.js
21
lib/scope.js
@@ -67,7 +67,10 @@ SymbolDef.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
|
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
|
options = defaults(options, {
|
||||||
|
screw_ie: false
|
||||||
|
});
|
||||||
// This does what ast_add_scope did in UglifyJS v1.
|
// This does what ast_add_scope did in UglifyJS v1.
|
||||||
//
|
//
|
||||||
// Part of it could be done at parse time, but it would complicate
|
// Part of it could be done at parse time, but it would complicate
|
||||||
@@ -121,13 +124,15 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
|
|||||||
node.init_scope_vars();
|
node.init_scope_vars();
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
//scope.def_function(node);
|
if (options.screw_ie) {
|
||||||
//
|
scope.def_function(node);
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/24 — MSIE
|
} else {
|
||||||
// leaks function expression names into the containing
|
// https://github.com/mishoo/UglifyJS2/issues/24 — MSIE
|
||||||
// scope. Don't like this fix but seems we can't do any
|
// leaks function expression names into the containing
|
||||||
// better. IE: please die. Please!
|
// scope. Don't like this fix but seems we can't do any
|
||||||
(node.scope = scope.parent_scope).def_function(node);
|
// better. IE: please die. Please!
|
||||||
|
(node.scope = scope.parent_scope).def_function(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolDefun) {
|
else if (node instanceof AST_SymbolDefun) {
|
||||||
// Careful here, the scope where this should be defined is
|
// Careful here, the scope where this should be defined is
|
||||||
|
|||||||
Reference in New Issue
Block a user