You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7d1d0f5
Browse filesBrowse the repository at this point in the historyBrowse files
* @typedef {object} InlineHooks what later phases add to inlining a variable's value
29229
+
* @property {((reference: Node, definition: SymbolDefinition, compressor: CompressorShape) => boolean) | null} inlinesIntoCallee whether a function read once, in another scope, is inlined where its value is only called
29230
+
* @property {((call: Node, lambda: Node, index: number, compressor: CompressorShape) => boolean) | null} aliasesParameter whether a parameter of a function flattened into its call, its name taken around the call, reads the argument's variable instead
29231
+
*/
29232
+
29096
29233
/**
29097
29234
* Builds webpack's `compress/inline.js`: a variable's value inlined into its
29098
29235
* reference, and a function inlined into its call.
"a function written in place passed the name of its parameter, a `let` read before it is set, or a global",
975
+
"function f() { try { return (function (a) { return [a, a]; })(a); } catch (e) { return e.name; } let a = 1; } function g() { return (function (b) { return [b, b]; })(b); } var b = 1; console.log(f(), g());"
976
+
],
977
+
[
978
+
"a function written in place passed the name of its parameter, a `var` read before it is set",
979
+
"function f() { var g = (function (a) { return [a, a]; })(a); var a = 1; return g; } console.log(f());"
980
+
],
981
+
[
982
+
"a function declared once, inlined where a conditional choosing it is called",
983
+
"!function () { function center(s) { return s + 1; } function number(s) { return s * 2; } function make(b) { return function (x) { return (b ? center : number)(x); }; } console.log(make(1)(3), make(0)(3)); }();"
984
+
],
985
+
[
986
+
"functions declared once, inlined where nested conditionals choosing them are called",
987
+
"!function () { function f1(s) { return s + 1; } function f2(s) { return s * 2; } function f3(s) { return s - 1; } function make(a, b) { return function (x) { return (a ? f1 : b ? f2 : f3)(x); }; } console.log(make(1, 0)(3), make(0, 1)(3), make(0, 0)(3)); }();"
988
+
],
989
+
[
990
+
"a function read in a conditional's test stays, those it chooses to call are inlined",
991
+
"!function () { function f1(s) { return s + 1; } function f2(s) { return s * 2; } function f3(s) { return s - 1; } function make(b) { return function (x) { return (f1(b) ? f2 : f3)(x); }; } console.log(make(1)(3), make(-1)(3)); }();"
992
+
],
993
+
[
994
+
"a function passed the variables of its parameters' names, set before the call, flattened into it",
995
+
"!function () { var log = []; function show(props, name) { props.get = function () { return name; }; log.push(props.get()); } function create(type, flag) { var props = {}, name = type.name; flag && show(props, name); return props; } console.log(create({ name: \"a\" }, 1).get(), create({ name: \"b\" }, 0).get, log.join()); }();"
996
+
],
997
+
[
998
+
"a function passed the variables of its parameters' names, flattened into it, no closure reading them",
999
+
"!function () { function show(props, name) { props.seen = name; } function create(type, flag) { if (flag) var props = {}; var name = type.name; flag && show(props, name); return props; } console.log(create({ name: \"a\" }, 1).seen, create({ name: \"b\" }, 0)); }();"
1000
+
],
1001
+
[
1002
+
"a function passed the parameters of its own parameters' names, flattened into it",
1003
+
"!function () { function show(props, name) { var n = name + 1; props.seen = n; } function create(props, name, flag) { flag && show(props, name); return props; } console.log(create({}, \"a\", 1).seen, create({}, \"b\", 0).seen); }();"
972
1004
]
973
1005
].map(
974
1006
([name,input])=>
@@ -1153,12 +1185,19 @@ const KEPT_CASES = [
1153
1185
["a function written in place calling `eval`",'function f(a) { return (function (a) { return [a, a, eval("a")]; })(a); } console.log(f(1));'],
1154
1186
["a function written in place with a default value","function f(a, b) { return (function (a, b = 2) { return [a, a, b]; })(a, b); } console.log(f(1));"],
1155
1187
["a function written in place passed a spread","function f(a, c) { return (function (a, b) { return [a, a, b]; })(a, ...c); } console.log(f(1, [2]));"],
1156
-
["a function written in place passed a `let` before it is set, or a global","function f() { try { return (function (a) { return [a, a]; })(a); } catch (e) { return e.name; } let a = 1; } function g() { return (function (b) { return [b, b]; })(b); } var b = 1; console.log(f(), g());"],
1157
-
["a function written in place passed a `var` before it is set","function f() { var g = (function (a) { return [a, a]; })(a); var a = 1; return g; } console.log(f());"],
1158
1188
["a function written in place passed a name declared twice, or declaring its parameter again","function f(a, b) { var a; return [(function (a) { return [a, a]; })(a), (function (b) { var b; return [b, b]; })(b)]; } console.log(f(1, 2));"],
1159
1189
["a function written in place passed a name a `with` may read","function f(a) { with ({}) return (function (a) { return [a, a]; })(a); } console.log(f(1));"],
1160
1190
["a function written in place passed an undeclared name","function f() { return (function (a) { return [a, a]; })(a); } try { console.log(f()); } catch (e) { console.log(e.name); }"],
1161
-
["a function written in place passed the name of its one parameter, which would stay called","function f(o) { return (function (o) { var t = o.a; return [t, t, o.b]; })(o); } console.log(f({ a: 1, b: 2 }));"]
1191
+
["a function written in place passed the name of its one parameter, which would stay called","function f(o) { return (function (o) { var t = o.a; return [t, t, o.b]; })(o); } console.log(f({ a: 1, b: 2 }));"],
1192
+
["functions calling themselves, chosen by a conditional that is called","!function () { function fact(n) { return n < 2 ? 1 : n * fact(n - 1); } function sum(n) { return n < 1 ? 0 : n + sum(n - 1); } function make(b) { return function (x) { return (b ? fact : sum)(x); }; } console.log(make(1)(4), make(0)(4)); }();"],
1193
+
["functions chosen by a conditional that is constructed or passed on","!function () { function P(s) { this.s = s; } function Q(s) { this.s = -s; } function f1(s) { return s + 1; } function f2(s) { return s * 2; } function make(b) { return function (x) { return [new (b ? P : Q)(x).s, [x].map(b ? f1 : f2)]; }; } console.log(make(1)(3), make(0)(3)); }();"],
1194
+
["a function passed variables of its parameters' names that a closure in it reads, set in a loop or after the call","!function () { var fs = []; function show(props, name) { props.get = function () { return name; }; } function create(list) { for (var i = 0; i < list.length; i++) { var props = {}, name = list[i]; list[i] && show(props, name); fs.push(props); } } function late(props, flag) { flag && show(props, name); var name = \"late\"; return props; } create([\"a\", \"b\"]); console.log(fs.map(function (p) { return p.get(); }).join(), late({}, 1).get()); }();"],
1195
+
["a function passed a variable of another name, or of its name but written","!function () { function show(props, name) { props.seen = name; } function other(props, value, name, flag) { flag && show(props, value); return [props, name]; } function written(props, name, flag) { flag && show(props, name); name = 2; return [props, name]; } console.log(other({}, \"a\", \"n\", 1)[0].seen, written({}, \"a\", 1)[0].seen); }();"],
1196
+
["a function passed variables of its parameters' names, which a pattern or a `for` head writes","!function () { function show(props, name) { props.get = function () { return name; }; } function pattern(props, name, flag) { flag && show(props, name); [name] = [\"later\"]; return props; } function head(props, name, flag) { flag && show(props, name); for (name in { later: 1 }); return props; } console.log(pattern({}, \"a\", 1).get(), head({}, \"a\", 1).get()); }();"],
1197
+
["a function incrementing a parameter, passed the variable of its name","!function () { function show(props, name) { props.seen = name++; props.next = name; } function create(props, name, flag) { flag && show(props, name); return [props, name]; } console.log(create({}, \"a\", 1)[0].next, create({}, 1, 1)[0].next); }();"],
1198
+
["a function writing a parameter by a pattern, passed the variable of its name","!function () { function show(props, name) { [name] = [name + \"!\"]; props.seen = name; } function create(props, name, flag) { flag && show(props, name); return [props, name]; } console.log(create({}, \"a\", 1)[0].seen, create({}, \"b\", 0)[0].seen); }();"],
1199
+
["a function passed variables of its parameters' names, of a function reading `arguments` or `eval`","!function () { function show(props, name) { props.seen = name; } function args(props, name, flag) { flag && show(props, name); return [props, name, arguments.length]; } function evaluates(props, name, flag) { flag && show(props, name); return [props, eval(\"name\")]; } console.log(args({}, \"a\", 1)[0].seen, evaluates({}, \"b\", 1)[0].seen); }();"],
1200
+
["a function passed a global of its parameter's name","var name = \"g\"; !function () { function show(props, name) { props.seen = name; } function create(props, flag) { flag && show(props, name); return props; } console.log(create({}, 1).seen, create({}, 0).seen); }();"]
1162
1201
];
1163
1202
1164
1203
// Each prints one thing and terser's output another, under the options named.
0 commit comments