enhance inline & module

This commit is contained in:
alexlamsl 2022-05-27 10:23:52 +08:00
parent 94aae05d45
commit 884c190d00
2 changed files with 30 additions and 6 deletions

View File

@ -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) {

View File

@ -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"
}