JS inline: save static ref to JsFunction in JsName

This commit is contained in:
Alexey Tsvetkov
2014-07-18 12:36:07 +04:00
committed by Zalim Bashorov
parent e4cd733879
commit 2e38833367
2 changed files with 17 additions and 0 deletions
@@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull;
public class JsName implements Symbol {
private final JsScope enclosing;
private final String ident;
private JsNode staticRef = null;
/**
* @param ident the unmangled ident to use for this name
@@ -26,6 +27,14 @@ public class JsName implements Symbol {
return ident;
}
public JsNode getStaticRef() {
return staticRef;
}
public void setStaticRef(JsNode staticRef) {
this.staticRef = staticRef;
}
@NotNull
public JsNameRef makeRef() {
return new JsNameRef(this);
@@ -20,6 +20,7 @@ import com.google.dart.compiler.backend.js.ast.JsExpression
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer
import com.google.dart.compiler.backend.js.ast.JsNameRef
import com.google.dart.compiler.backend.js.ast.JsObjectScope
import com.google.dart.compiler.backend.js.ast.JsFunction
class DefinitionPlace(
private val scope: JsObjectScope,
@@ -28,6 +29,13 @@ class DefinitionPlace(
) {
fun define(suggestedName: String, expression : JsExpression): JsNameRef {
val name = scope.declareFreshName(suggestedName)
if (expression is JsFunction) {
/** JsInliner should be able
* to find function by name */
name.setStaticRef(expression)
}
properties.add(JsPropertyInitializer(name.makeRef(), expression))
return JsNameRef(name, fqName)
}