Skip to content

Commit a4aee39

Browse files
varomodtcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 789729979
1 parent 844f501 commit a4aee39

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/com/google/javascript/jscomp/InlineFunctionsTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,71 @@ function foo(){ return 4 }
257257
"4");
258258
}
259259

260+
@Test
261+
public void testInlineFunctions1_arrowFn() {
262+
test(
263+
"""
264+
const foo = () => 4;
265+
foo();
266+
""",
267+
"4");
268+
}
269+
270+
@Test
271+
public void testInlineFunctions1_arrowFn_block() {
272+
test(
273+
"""
274+
const foo = () => { return 4; };
275+
foo();
276+
""",
277+
"4");
278+
}
279+
280+
@Test
281+
public void testInlineFunctions1_inArrowFn() {
282+
test(
283+
"""
284+
const foo = () => 4;
285+
(() => foo())();
286+
""",
287+
"4");
288+
}
289+
290+
@Test
291+
public void testInlineFunctions1_inArrowFn_block() {
292+
test(
293+
"""
294+
const foo = () => 4;
295+
(() => {
296+
let a = foo();
297+
[].forEach(() => a += 1);
298+
return a;
299+
})();
300+
""",
301+
// Why is the IIFE not inlined here?
302+
// This happens whether or not the function references
303+
// a local.
304+
"""
305+
(() => {
306+
let a = 4;
307+
[].forEach(() => {
308+
return a = a + 1;
309+
});
310+
return a;
311+
})();
312+
""");
313+
}
314+
315+
@Test
316+
public void testInlineFunctions1_arrowFnArg() {
317+
test(
318+
"""
319+
const bar = (f) => f();
320+
bar(() => 4);
321+
""",
322+
"4");
323+
}
324+
260325
@Test
261326
public void testInlineFunctions2() {
262327
// inline simple constants

0 commit comments

Comments
 (0)