[JS IR] Lower lambdas into in-line anonymous functions when possible

Previously we always generated factories for contextful lambdas:

```kt
fun foo(a: Int) = { a }
```

```js
function foo(a_38) {
  return foo$lambda(a_38);
}

// factory!
function foo$lambda($a) {
  return function () {
    return $a;
  };
}
```

After this patch, the generated code for `foo` is more concise:

```js
function foo(a) {
  return function() { return a; };
}
```
This commit is contained in:
Sergej Jaskiewicz
2022-04-04 18:11:52 +03:00
committed by Space
parent 5b61e60f2f
commit c10af22b27
5 changed files with 350 additions and 26 deletions
@@ -356,6 +356,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/closure/closureArrayListInstance.kt");
}
@Test
@TestMetadata("closureCodeSize.kt")
public void testClosureCodeSize() throws Exception {
runTest("js/js.translator/testData/box/closure/closureCodeSize.kt");
}
@Test
@TestMetadata("closureFunctionAsArgument.kt")
public void testClosureFunctionAsArgument() throws Exception {
@@ -356,6 +356,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/closure/closureArrayListInstance.kt");
}
@Test
@TestMetadata("closureCodeSize.kt")
public void testClosureCodeSize() throws Exception {
runTest("js/js.translator/testData/box/closure/closureCodeSize.kt");
}
@Test
@TestMetadata("closureFunctionAsArgument.kt")
public void testClosureFunctionAsArgument() throws Exception {