document reason why we don't declare ecma 5 property name as obfuscatable
use standard backing field name prefix for ecma 5 (was: _, must be: $)
This commit is contained in:
@@ -153,6 +153,14 @@ public final class StaticContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class NameGenerator extends Generator<JsName> {
|
private final class NameGenerator extends Generator<JsName> {
|
||||||
|
private JsName declareName(DeclarationDescriptor descriptor, String name) {
|
||||||
|
NamingScope scope = getEnclosingScope(descriptor);
|
||||||
|
// ecma 5 property name never declares as obfuscatable:
|
||||||
|
// 1) property cannot be overloaded, so, name collision is not possible
|
||||||
|
// 2) main reason: if property doesn't have any custom accessor, value holder will have the same name as accessor, so, the same name will be declared more than once
|
||||||
|
return isEcma5() ? scope.declareUnobfuscatableName(name) : scope.declareObfuscatableName(name);
|
||||||
|
}
|
||||||
|
|
||||||
public NameGenerator() {
|
public NameGenerator() {
|
||||||
Rule<JsName> namesForStandardClasses = new Rule<JsName>() {
|
Rule<JsName> namesForStandardClasses = new Rule<JsName>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -203,11 +211,9 @@ public final class StaticContext {
|
|||||||
boolean isGetter = descriptor instanceof PropertyGetterDescriptor;
|
boolean isGetter = descriptor instanceof PropertyGetterDescriptor;
|
||||||
PropertyAccessorDescriptor accessorDescriptor = (PropertyAccessorDescriptor) descriptor;
|
PropertyAccessorDescriptor accessorDescriptor = (PropertyAccessorDescriptor) descriptor;
|
||||||
String propertyName = accessorDescriptor.getCorrespondingProperty().getName().getName();
|
String propertyName = accessorDescriptor.getCorrespondingProperty().getName().getName();
|
||||||
String accessorName = Namer.getNameForAccessor(propertyName, isGetter, !accessorDescriptor.getReceiverParameter().exists() && isEcma5());
|
String accessorName = Namer.getNameForAccessor(propertyName, isGetter,
|
||||||
NamingScope enclosingScope = getEnclosingScope(descriptor);
|
!accessorDescriptor.getReceiverParameter().exists() && isEcma5());
|
||||||
return isEcma5()
|
return declareName(descriptor, accessorName);
|
||||||
? enclosingScope.declareUnobfuscatableName(accessorName)
|
|
||||||
: enclosingScope.declareObfuscatableName(accessorName);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -232,19 +238,12 @@ public final class StaticContext {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: move somewhere
|
String name = descriptor.getName().getName();
|
||||||
NamingScope enclosingScope = getEnclosingScope(descriptor);
|
if (!isEcma5() || JsDescriptorUtils.isAsPrivate((PropertyDescriptor) descriptor)) {
|
||||||
if (isEcma5()) {
|
name = Namer.getKotlinBackingFieldName(name);
|
||||||
String name = descriptor.getName().getName();
|
}
|
||||||
if (JsDescriptorUtils.isAsPrivate((PropertyDescriptor) descriptor)) {
|
|
||||||
name = '_' + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return enclosingScope.declareUnobfuscatableName(name);
|
return declareName(descriptor, name);
|
||||||
}
|
|
||||||
else {
|
|
||||||
return enclosingScope.declareObfuscatableName(Namer.getKotlinBackingFieldName(descriptor.getName().getName()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//TODO: hack!
|
//TODO: hack!
|
||||||
|
|||||||
Reference in New Issue
Block a user