implement multinamespace translation:
excluded generation of empty(declaration only) namespaces
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package js;
|
||||
|
||||
native
|
||||
annotation class native(name : String = "") {}
|
||||
native
|
||||
annotation class library(name : String = "") {}
|
||||
@@ -4,7 +4,7 @@ import js.*;
|
||||
|
||||
|
||||
library("collectionsMax")
|
||||
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = f
|
||||
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T {}
|
||||
|
||||
library
|
||||
public trait Comparator<T> {
|
||||
@@ -24,11 +24,9 @@ public open class Iterator<T>() {
|
||||
library
|
||||
val Collections = object {
|
||||
library("collectionsMax")
|
||||
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = f
|
||||
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = js.noImpl
|
||||
}
|
||||
|
||||
private val f : Nothing
|
||||
|
||||
library
|
||||
public open class ArrayList<erased E>() : java.util.List<E> {
|
||||
override public fun size() : Int {}
|
||||
|
||||
@@ -6,11 +6,6 @@ import js.native
|
||||
native
|
||||
fun JQuery.pixastic(actionName : String) = js.noImpl
|
||||
|
||||
|
||||
native
|
||||
object Pixastic {
|
||||
}
|
||||
|
||||
native
|
||||
fun addAction(actionName : String,
|
||||
process : (oldData : Array<Int>, newData : Array<Int>, width : Int, height : Int)->Unit) = js.noImpl
|
||||
@@ -139,16 +139,6 @@ public final class StaticContext {
|
||||
|
||||
private final class NameGenerator extends Generator<JsName> {
|
||||
public NameGenerator() {
|
||||
Rule<JsName> aliasOverridesNames = new Rule<JsName>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public JsName apply(@NotNull DeclarationDescriptor data) {
|
||||
if (aliaser.hasAliasForDeclaration(data)) {
|
||||
return aliaser.getAliasForDeclaration(data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Rule<JsName> namesForStandardClasses = new Rule<JsName>() {
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -294,7 +284,6 @@ public final class StaticContext {
|
||||
}
|
||||
};
|
||||
addRule(namesForStandardClasses);
|
||||
addRule(aliasOverridesNames);
|
||||
addRule(constructorHasTheSameNameAsTheClass);
|
||||
addRule(namesAnnotatedAsLibraryHasUnobfuscatableNames);
|
||||
addRule(namesForNativeObjectsAreUnobfuscatable);
|
||||
|
||||
@@ -125,12 +125,11 @@ public final class ClassTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression getClassReference(@NotNull ClassDescriptor superClassDescriptor) {
|
||||
//TODO we actually know that in current implementation superclass must have an alias but
|
||||
// in future it might change
|
||||
if (aliaser().hasAliasForDeclaration(superClassDescriptor)) {
|
||||
//NOTE: aliasing here is needed for the declaration generation step
|
||||
if (context().aliaser().hasAliasForDeclaration(superClassDescriptor)) {
|
||||
return context().aliaser().getAliasForDeclaration(superClassDescriptor).makeRef();
|
||||
}
|
||||
throw new AssertionError("Inherited from unknown class");
|
||||
return context().getNameForDescriptor(superClassDescriptor).makeRef();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,12 +44,20 @@ public final class NamespaceTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
public JsStatement translateNamespace() {
|
||||
if (isNamespaceEmpty()) {
|
||||
return program().getEmptyStmt();
|
||||
}
|
||||
classDeclarationTranslator.generateDeclarations();
|
||||
return AstUtil.newBlock(classDeclarationsStatement(),
|
||||
namespaceOwnDeclarationStatement(),
|
||||
namespaceInitializeStatement());
|
||||
}
|
||||
|
||||
//TODO: at the moment this check is very ineffective, possible solution is to cash the result of getDFN
|
||||
private boolean isNamespaceEmpty() {
|
||||
return BindingUtils.getDeclarationsForNamespace(context().bindingContext(), namespace).isEmpty();
|
||||
}
|
||||
|
||||
private JsStatement classDeclarationsStatement() {
|
||||
return classDeclarationTranslator.getDeclarationsStatement();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user