enhance inline & module (#5475)
This commit is contained in:
@@ -2554,7 +2554,8 @@ Compressor.prototype.compress = function(node) {
|
||||
&& all(iife.args, function(arg) {
|
||||
return !(arg instanceof AST_Spread);
|
||||
})) {
|
||||
var fn_strict = fn.in_strict_mode() && !fn.parent_scope.resolve(true).in_strict_mode();
|
||||
var fn_strict = fn.in_strict_mode(compressor)
|
||||
&& !fn.parent_scope.resolve(true).in_strict_mode(compressor);
|
||||
var has_await = is_async(fn) ? function(node) {
|
||||
return node instanceof AST_Symbol && node.name == "await";
|
||||
} : function(node) {
|
||||
@@ -4124,8 +4125,8 @@ Compressor.prototype.compress = function(node) {
|
||||
// in_strict_mode()
|
||||
// return true if scope executes in Strict Mode
|
||||
(function(def) {
|
||||
def(AST_Class, return_this);
|
||||
def(AST_Scope, function() {
|
||||
def(AST_Class, return_true);
|
||||
def(AST_Scope, function(compressor) {
|
||||
var body = this.body;
|
||||
for (var i = 0; i < body.length; i++) {
|
||||
var stat = body[i];
|
||||
@@ -4133,8 +4134,8 @@ Compressor.prototype.compress = function(node) {
|
||||
if (stat.value == "use strict") return true;
|
||||
}
|
||||
var parent = this.parent_scope;
|
||||
if (!parent) return false;
|
||||
return parent.resolve(true).in_strict_mode();
|
||||
if (!parent) return compressor.option("module");
|
||||
return parent.resolve(true).in_strict_mode(compressor);
|
||||
});
|
||||
})(function(node, func) {
|
||||
node.DEFMETHOD("in_strict_mode", func);
|
||||
@@ -9941,7 +9942,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
|
||||
function safe_from_strict_mode(fn, compressor) {
|
||||
return fn.in_strict_mode() || !compressor.has_directive("use strict");
|
||||
return fn.in_strict_mode(compressor) || !compressor.has_directive("use strict");
|
||||
}
|
||||
|
||||
OPT(AST_Call, function(self, compressor) {
|
||||
|
||||
@@ -8623,3 +8623,26 @@ mixed_mode_inline_4_strict: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
module_inline: {
|
||||
options = {
|
||||
inline: true,
|
||||
module: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = f;
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
console.log(f() === a);
|
||||
}
|
||||
expect: {
|
||||
var a = f;
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
console.log(a === a);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user