implement inline levels
add tests update docs
This commit is contained in:
parent
2a9934e485
commit
1dbe97c655
|
|
@ -640,7 +640,13 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||||
|
|
||||||
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
||||||
|
|
||||||
- `inline` (default: `true`) -- embed simple functions
|
- `inline` (default: `true`) -- inline calls to function with simple/`return` statement:
|
||||||
|
- `false` -- same as `0`
|
||||||
|
- `0` -- disabled inlining
|
||||||
|
- `1` -- inline simple functions
|
||||||
|
- `2` -- inline functions with arguments
|
||||||
|
- `3` -- inline functions with arguments and variables
|
||||||
|
- `true` -- same as `3`
|
||||||
|
|
||||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ function Compressor(options, false_by_default) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.options["inline"] === true) this.options["inline"] = 3;
|
||||||
var pure_funcs = this.options["pure_funcs"];
|
var pure_funcs = this.options["pure_funcs"];
|
||||||
if (typeof pure_funcs == "function") {
|
if (typeof pure_funcs == "function") {
|
||||||
this.pure_funcs = pure_funcs;
|
this.pure_funcs = pure_funcs;
|
||||||
|
|
@ -4073,6 +4074,7 @@ merge(Compressor.prototype, {
|
||||||
function can_flatten_body() {
|
function can_flatten_body() {
|
||||||
var len = fn.body.length;
|
var len = fn.body.length;
|
||||||
if (len == 1) return true;
|
if (len == 1) return true;
|
||||||
|
if (compressor.option("inline") < 3) return false;
|
||||||
stat = null;
|
stat = null;
|
||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
var line = fn.body[i];
|
var line = fn.body[i];
|
||||||
|
|
@ -4139,9 +4141,10 @@ merge(Compressor.prototype, {
|
||||||
if (scope.fixed_value() instanceof AST_Scope) return false;
|
if (scope.fixed_value() instanceof AST_Scope) return false;
|
||||||
}
|
}
|
||||||
} while (!(scope instanceof AST_Scope));
|
} while (!(scope instanceof AST_Scope));
|
||||||
var safe_to_inject = compressor.toplevel.vars || !(scope instanceof AST_Toplevel);
|
var safe_to_inject = !(scope instanceof AST_Toplevel) || compressor.toplevel.vars;
|
||||||
if (!can_inject_vars(catches, in_loop, safe_to_inject)) return false;
|
var inline = compressor.option("inline");
|
||||||
if (!can_inject_args(catches, in_loop, safe_to_inject)) return false;
|
if (!can_inject_vars(catches, in_loop, inline >= 3 && safe_to_inject)) return false;
|
||||||
|
if (!can_inject_args(catches, in_loop, inline >= 2 && safe_to_inject)) return false;
|
||||||
return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop);
|
return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1694,3 +1694,210 @@ loop_init_arg: {
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline_false: {
|
||||||
|
options = {
|
||||||
|
inline: false,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_0: {
|
||||||
|
options = {
|
||||||
|
inline: 0,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_1: {
|
||||||
|
options = {
|
||||||
|
inline: 1,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_2: {
|
||||||
|
options = {
|
||||||
|
inline: 2,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
a = 2, console.log(a);
|
||||||
|
var a;
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_3: {
|
||||||
|
options = {
|
||||||
|
inline: 3,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
a = 2, console.log(a);
|
||||||
|
var a;
|
||||||
|
b = 3, c = b, console.log(c);
|
||||||
|
var b, c;
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_true: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
console.log(1);
|
||||||
|
})();
|
||||||
|
(function(a) {
|
||||||
|
console.log(a);
|
||||||
|
})(2);
|
||||||
|
(function(b) {
|
||||||
|
var c = b;
|
||||||
|
console.log(c);
|
||||||
|
})(3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
a = 2, console.log(a);
|
||||||
|
var a;
|
||||||
|
b = 3, c = b, console.log(c);
|
||||||
|
var b, c;
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user