remove compress hack in favor of @alexlamsl's AST_Function suggestion
This commit is contained in:
parent
f3332f591e
commit
1fe2422f80
|
|
@ -409,7 +409,6 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node instanceof AST_DefClass || node instanceof AST_Defun) {
|
if (node instanceof AST_DefClass || node instanceof AST_Defun) {
|
||||||
if (!node.name) return;
|
|
||||||
node.inlined = false;
|
node.inlined = false;
|
||||||
var d = node.name.definition();
|
var d = node.name.definition();
|
||||||
if (compressor.exposed(d) || safe_to_read(d)) {
|
if (compressor.exposed(d) || safe_to_read(d)) {
|
||||||
|
|
@ -2582,7 +2581,6 @@ merge(Compressor.prototype, {
|
||||||
if (node instanceof AST_Defun || node instanceof AST_DefClass) {
|
if (node instanceof AST_Defun || node instanceof AST_DefClass) {
|
||||||
var in_export = tw.parent() instanceof AST_Export;
|
var in_export = tw.parent() instanceof AST_Export;
|
||||||
if (in_export || !drop_funcs && scope === self) {
|
if (in_export || !drop_funcs && scope === self) {
|
||||||
if (!node.name) return;
|
|
||||||
var node_def = node.name.definition();
|
var node_def = node.name.definition();
|
||||||
if (node_def.global && !(node_def.id in in_use_ids)) {
|
if (node_def.global && !(node_def.id in in_use_ids)) {
|
||||||
in_use_ids[node_def.id] = true;
|
in_use_ids[node_def.id] = true;
|
||||||
|
|
@ -2668,7 +2666,6 @@ merge(Compressor.prototype, {
|
||||||
if (node.name
|
if (node.name
|
||||||
&& (!compressor.option("keep_classnames") && node instanceof AST_ClassExpression
|
&& (!compressor.option("keep_classnames") && node instanceof AST_ClassExpression
|
||||||
|| !compressor.option("keep_fnames") && node instanceof AST_Function)) {
|
|| !compressor.option("keep_fnames") && node instanceof AST_Function)) {
|
||||||
if (!node.name) return;
|
|
||||||
var def = node.name.definition();
|
var def = node.name.definition();
|
||||||
// any declarations with same name will overshadow
|
// any declarations with same name will overshadow
|
||||||
// name of this anonymous function and can therefore
|
// name of this anonymous function and can therefore
|
||||||
|
|
@ -2704,7 +2701,6 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
||||||
if (!node.name) return;
|
|
||||||
var def = node.name.definition();
|
var def = node.name.definition();
|
||||||
var keep = (def.id in in_use_ids) || !drop_funcs && def.global;
|
var keep = (def.id in in_use_ids) || !drop_funcs && def.global;
|
||||||
if (!keep) {
|
if (!keep) {
|
||||||
|
|
|
||||||
13
lib/parse.js
13
lib/parse.js
|
|
@ -1310,7 +1310,7 @@ function parse($TEXT, options) {
|
||||||
|
|
||||||
var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
|
var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
|
||||||
if (is_generator_property && is_async) croak("generators cannot be async");
|
if (is_generator_property && is_async) croak("generators cannot be async");
|
||||||
var start = S.token
|
var start = S.token;
|
||||||
|
|
||||||
var in_statement = ctor === AST_Defun;
|
var in_statement = ctor === AST_Defun;
|
||||||
var is_generator = is("operator", "*");
|
var is_generator = is("operator", "*");
|
||||||
|
|
@ -1319,8 +1319,13 @@ function parse($TEXT, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||||
if (in_statement && !name && !is_export_default)
|
if (in_statement && !name) {
|
||||||
unexpected();
|
if (is_export_default) {
|
||||||
|
ctor = AST_Function;
|
||||||
|
} else {
|
||||||
|
unexpected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||||
unexpected(prev());
|
unexpected(prev());
|
||||||
|
|
@ -2530,7 +2535,7 @@ function parse($TEXT, options) {
|
||||||
semicolon();
|
semicolon();
|
||||||
} else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
|
} else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
|
||||||
unexpected(node.start);
|
unexpected(node.start);
|
||||||
} else if (node instanceof AST_Definitions || node instanceof AST_Defun || node instanceof AST_DefClass) {
|
} else if (node instanceof AST_Definitions || node instanceof AST_Lambda || node instanceof AST_DefClass) {
|
||||||
exported_definition = node;
|
exported_definition = node;
|
||||||
} else if (node instanceof AST_SimpleStatement) {
|
} else if (node instanceof AST_SimpleStatement) {
|
||||||
exported_value = node.body;
|
exported_value = node.body;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user