JS: optimize variable representation in coroutines
Don't convert local variables to fields of coroutine object when variable is both used and defined in a single block.
This commit is contained in:
@@ -912,6 +912,21 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/coroutines")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Coroutines extends AbstractBoxJsTest {
|
||||
public void testAllFilesPresentInCoroutines() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/coroutines"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("localVarOptimization.kt")
|
||||
public void testLocalVarOptimization() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/coroutines/localVarOptimization.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/box/crossModuleRef")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -299,6 +299,27 @@ public class DirectiveTestUtils {
|
||||
}
|
||||
};
|
||||
|
||||
private static final DirectiveHandler DECLARES_VARIABLE = new DirectiveHandler("DECLARES_VARIABLE") {
|
||||
@Override
|
||||
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
||||
String functionName = arguments.getNamedArgument("function");
|
||||
String varName = arguments.getNamedArgument("name");
|
||||
JsFunction function = AstSearchUtil.getFunction(ast, functionName);
|
||||
boolean[] varDeclared = new boolean[1];
|
||||
function.accept(new RecursiveJsVisitor() {
|
||||
@Override
|
||||
public void visit(@NotNull JsVars.JsVar x) {
|
||||
super.visit(x);
|
||||
if (x.getName().getIdent().equals(varName)) {
|
||||
varDeclared[0] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue("Function " + functionName + " does not declare variable " + varName, varDeclared[0]);
|
||||
}
|
||||
};
|
||||
|
||||
private static final List<DirectiveHandler> DIRECTIVE_HANDLERS = Arrays.asList(
|
||||
FUNCTION_CONTAINS_NO_CALLS,
|
||||
FUNCTION_NOT_CALLED,
|
||||
@@ -319,7 +340,8 @@ public class DirectiveTestUtils {
|
||||
NOT_REFERENCED,
|
||||
HAS_INLINE_METADATA,
|
||||
HAS_NO_INLINE_METADATA,
|
||||
HAS_NO_CAPTURED_VARS
|
||||
HAS_NO_CAPTURED_VARS,
|
||||
DECLARES_VARIABLE
|
||||
);
|
||||
|
||||
public static void processDirectives(@NotNull JsNode ast, @NotNull String sourceCode) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user