Skip to content

Commit bb8b072

Browse files
fix(javascript): keep @__NOINLINE__ and yield/await IIFEs as calls
The improve phase moved a function's body into its caller even when the call was marked @__NOINLINE__, which terser honors, or when the body named yield or await, which a generator or async caller reads as its own. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 08eca1f commit bb8b072

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19062,7 +19062,8 @@ const installImprove = (modules) => {
1906219062

1906319063
/**
1906419064
* Whether a node reads the `this`, `arguments`, `new.target` or `super` of
19065-
* the function around it, through the arrows sharing them.
19065+
* the function around it, through the arrows sharing them, or names `yield`
19066+
* or `await`, which a generator or async function around it reads as its own.
1906619067
* @param {Node} node a node
1906719068
* @returns {boolean} true when it does
1906819069
*/
@@ -19079,7 +19080,9 @@ const installImprove = (modules) => {
1907919080
if (
1908019081
inner instanceof A.AST_This ||
1908119082
inner instanceof A.AST_NewTarget ||
19082-
(inner instanceof A.AST_SymbolRef && inner.name === "arguments")
19083+
(inner instanceof A.AST_SymbolRef && inner.name === "arguments") ||
19084+
(inner instanceof A.AST_Symbol &&
19085+
(inner.name === "yield" || inner.name === "await"))
1908319086
) {
1908419087
reads = true;
1908519088
}
@@ -19147,7 +19150,8 @@ const installImprove = (modules) => {
1914719150
!(call instanceof A.AST_Call) ||
1914819151
call instanceof A.AST_New ||
1914919152
call.optional ||
19150-
call.args.length > 0
19153+
call.args.length > 0 ||
19154+
(call._annotations & A._NOINLINE) !== 0
1915119155
) {
1915219156
return undefined;
1915319157
}

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
// cspell:ignore binop, fnames, propmangle, fargs, domprops, argnames, nondeferred, loopcontrol, Defun, defun
3+
// cspell:ignore binop, fnames, propmangle, fargs, domprops, argnames, nondeferred, loopcontrol, Defun, defun, NOINLINE
44

55
const vm = require("vm");
66
const {
@@ -249,7 +249,10 @@ const KEPT_CASES = [
249249
["`new`", `new function () { ${TRY} console.log(2); }();`],
250250
["an optional call", `(() => { ${TRY} console.log(2); })?.();`],
251251
["its value used", `console.log(function () { ${TRY} console.log(2); }());`],
252-
["a sequence calling nothing in place", "console.log(1); console.log(2);"]
252+
["a sequence calling nothing in place", "console.log(1); console.log(2);"],
253+
["`@__NOINLINE__`", `/*@__NOINLINE__*/(function () { ${TRY} console.log(2); })();`],
254+
["a `yield` identifier", `function* g() { !function () { ${TRY} console.log(yield); }(); } g().next();`],
255+
["an `await` identifier", `async function f() { !function () { ${TRY} console.log(await); }(); } f();`]
253256
];
254257

255258
// Each prints one thing and terser's output another, under the options named.

0 commit comments

Comments
 (0)