enhance inline & module (#5475)

This commit is contained in:
Alex Lam S.L
2022-05-27 04:57:05 +01:00
committed by GitHub
parent 94aae05d45
commit 2152f00de2
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) { && all(iife.args, function(arg) {
return !(arg instanceof AST_Spread); 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) { var has_await = is_async(fn) ? function(node) {
return node instanceof AST_Symbol && node.name == "await"; return node instanceof AST_Symbol && node.name == "await";
} : function(node) { } : function(node) {
@@ -4124,8 +4125,8 @@ Compressor.prototype.compress = function(node) {
// in_strict_mode() // in_strict_mode()
// return true if scope executes in Strict Mode // return true if scope executes in Strict Mode
(function(def) { (function(def) {
def(AST_Class, return_this); def(AST_Class, return_true);
def(AST_Scope, function() { def(AST_Scope, function(compressor) {
var body = this.body; var body = this.body;
for (var i = 0; i < body.length; i++) { for (var i = 0; i < body.length; i++) {
var stat = body[i]; var stat = body[i];
@@ -4133,8 +4134,8 @@ Compressor.prototype.compress = function(node) {
if (stat.value == "use strict") return true; if (stat.value == "use strict") return true;
} }
var parent = this.parent_scope; var parent = this.parent_scope;
if (!parent) return false; if (!parent) return compressor.option("module");
return parent.resolve(true).in_strict_mode(); return parent.resolve(true).in_strict_mode(compressor);
}); });
})(function(node, func) { })(function(node, func) {
node.DEFMETHOD("in_strict_mode", func); node.DEFMETHOD("in_strict_mode", func);
@@ -9941,7 +9942,7 @@ Compressor.prototype.compress = function(node) {
} }
function safe_from_strict_mode(fn, compressor) { 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) { OPT(AST_Call, function(self, compressor) {

View File

@@ -8623,3 +8623,26 @@ mixed_mode_inline_4_strict: {
} }
expect_stdout: "PASS" 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"
}