function inside function supported
This commit is contained in:
@@ -4,7 +4,6 @@ import js.annotations.native
|
|||||||
|
|
||||||
native
|
native
|
||||||
val Math = object {
|
val Math = object {
|
||||||
native
|
|
||||||
fun random() : Double = 0.0;
|
fun random() : Double = 0.0;
|
||||||
fun abs(value : Double) = 0.0
|
fun abs(value : Double) = 0.0
|
||||||
fun acos(value : Double) = 0.0
|
fun acos(value : Double) = 0.0
|
||||||
@@ -18,6 +17,7 @@ val Math = object {
|
|||||||
fun min(vararg values : Double) = 0.0
|
fun min(vararg values : Double) = 0.0
|
||||||
fun sqrt(value : Double) = 0.0
|
fun sqrt(value : Double) = 0.0
|
||||||
fun tan(value : Double) = 0.0
|
fun tan(value : Double) = 0.0
|
||||||
|
|
||||||
fun log(value : Double) = 0.0
|
fun log(value : Double) = 0.0
|
||||||
fun pow(base : Double, exp : Double) = 0.0
|
fun pow(base : Double, exp : Double) = 0.0
|
||||||
fun round(value : Double) = 0.0
|
fun round(value : Double) = 0.0
|
||||||
|
|||||||
@@ -395,4 +395,11 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
|||||||
JsExpression value = ClassTranslator.generateClassCreationExpression(expression, context);
|
JsExpression value = ClassTranslator.generateClassCreationExpression(expression, context);
|
||||||
return AstUtil.newVar(propertyName, value);
|
return AstUtil.newVar(propertyName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public JsNode visitNamedFunction(@NotNull JetNamedFunction function,
|
||||||
|
@NotNull TranslationContext context) {
|
||||||
|
return FunctionTranslator.newInstance(function, context).translateAsLocalFunction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,17 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
this.functionBodyContext = functionBodyContext().innerBlock(functionBody);
|
this.functionBodyContext = functionBodyContext().innerBlock(functionBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JsFunction translateAsLocalFunction() {
|
||||||
|
JsName functionName = context().getNameForElement(functionDeclaration);
|
||||||
|
JsFunction function = generateFunctionObject();
|
||||||
|
function.setName(functionName);
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsPropertyInitializer translateAsMethod() {
|
public JsPropertyInitializer translateAsMethod() {
|
||||||
assert functionDeclaration instanceof JetElement;
|
|
||||||
JsName functionName = context().getNameForElement(functionDeclaration);
|
JsName functionName = context().getNameForElement(functionDeclaration);
|
||||||
JsFunction function = generateFunctionObject();
|
JsFunction function = generateFunctionObject();
|
||||||
return new JsPropertyInitializer(functionName.makeRef(), function);
|
return new JsPropertyInitializer(functionName.makeRef(), function);
|
||||||
|
|||||||
@@ -86,4 +86,8 @@ public class FunctionTest extends AbstractExpressionTest {
|
|||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFunctionInsideFunction() throws Exception {
|
||||||
|
testFooBoxIsTrue("functionInsideFunction.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
|
||||||
|
fun box() : Boolean{
|
||||||
|
fun f() = 3
|
||||||
|
|
||||||
|
return (((f() + f()) == 6) && (b() == 24))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun b() : Int {
|
||||||
|
|
||||||
|
fun a() : Int {
|
||||||
|
fun c() = 4
|
||||||
|
return c() * 3
|
||||||
|
}
|
||||||
|
val a = 2
|
||||||
|
return a() * a
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user