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