Avoid duplication of imports introduced during JS inlining

This commit is contained in:
Alexey Andreev
2017-07-14 16:46:04 +03:00
parent f2b2e20331
commit 8c256b24dc
19 changed files with 374 additions and 76 deletions
+1
View File
@@ -426,6 +426,7 @@ message Name {
required bool temporary = 1;
optional int32 identifier = 2;
optional int32 local_name_id = 3;
optional bool imported = 4 [default = false];
}
@@ -91,7 +91,9 @@ class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<Fi
}
for (nameBinding in fragment.nameBindings) {
nameBinding.name.imported = nameBinding.key in fragment.imports
if (nameBinding.key in fragment.imports) {
nameBinding.name.imported = true
}
}
return fragment
@@ -438,6 +440,9 @@ class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<Fi
if (nameProto.hasLocalNameId()) {
name.localAlias = deserializeName(nameProto.localNameId)
}
if (nameProto.hasImported()) {
name.imported = nameProto.imported
}
nameCache[id] = name
name
}
@@ -34763,6 +34763,15 @@ public final class JsAstProtoBuf {
* <code>optional int32 local_name_id = 3;</code>
*/
int getLocalNameId();
/**
* <code>optional bool imported = 4;</code>
*/
boolean hasImported();
/**
* <code>optional bool imported = 4;</code>
*/
boolean getImported();
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.js.ast.Name}
@@ -34829,6 +34838,11 @@ public final class JsAstProtoBuf {
localNameId_ = input.readInt32();
break;
}
case 32: {
bitField0_ |= 0x00000008;
imported_ = input.readBool();
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -34908,10 +34922,26 @@ public final class JsAstProtoBuf {
return localNameId_;
}
public static final int IMPORTED_FIELD_NUMBER = 4;
private boolean imported_;
/**
* <code>optional bool imported = 4;</code>
*/
public boolean hasImported() {
return ((bitField0_ & 0x00000008) == 0x00000008);
}
/**
* <code>optional bool imported = 4;</code>
*/
public boolean getImported() {
return imported_;
}
private void initFields() {
temporary_ = false;
identifier_ = 0;
localNameId_ = 0;
imported_ = false;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -34939,6 +34969,9 @@ public final class JsAstProtoBuf {
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeInt32(3, localNameId_);
}
if (((bitField0_ & 0x00000008) == 0x00000008)) {
output.writeBool(4, imported_);
}
output.writeRawBytes(unknownFields);
}
@@ -34960,6 +34993,10 @@ public final class JsAstProtoBuf {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(3, localNameId_);
}
if (((bitField0_ & 0x00000008) == 0x00000008)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeBoolSize(4, imported_);
}
size += unknownFields.size();
memoizedSerializedSize = size;
return size;
@@ -35060,6 +35097,8 @@ public final class JsAstProtoBuf {
bitField0_ = (bitField0_ & ~0x00000002);
localNameId_ = 0;
bitField0_ = (bitField0_ & ~0x00000004);
imported_ = false;
bitField0_ = (bitField0_ & ~0x00000008);
return this;
}
@@ -35095,6 +35134,10 @@ public final class JsAstProtoBuf {
to_bitField0_ |= 0x00000004;
}
result.localNameId_ = localNameId_;
if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
to_bitField0_ |= 0x00000008;
}
result.imported_ = imported_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -35110,6 +35153,9 @@ public final class JsAstProtoBuf {
if (other.hasLocalNameId()) {
setLocalNameId(other.getLocalNameId());
}
if (other.hasImported()) {
setImported(other.getImported());
}
setUnknownFields(
getUnknownFields().concat(other.unknownFields));
return this;
@@ -35238,6 +35284,38 @@ public final class JsAstProtoBuf {
return this;
}
private boolean imported_ ;
/**
* <code>optional bool imported = 4;</code>
*/
public boolean hasImported() {
return ((bitField0_ & 0x00000008) == 0x00000008);
}
/**
* <code>optional bool imported = 4;</code>
*/
public boolean getImported() {
return imported_;
}
/**
* <code>optional bool imported = 4;</code>
*/
public Builder setImported(boolean value) {
bitField0_ |= 0x00000008;
imported_ = value;
return this;
}
/**
* <code>optional bool imported = 4;</code>
*/
public Builder clearImported() {
bitField0_ = (bitField0_ & ~0x00000008);
imported_ = false;
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.js.ast.Name)
}
@@ -33,8 +33,12 @@ class JsAstSerializer(private val pathResolver: (File) -> String) {
private val nameMap = mutableMapOf<JsName, Int>()
private val stringMap = mutableMapOf<String, Int>()
private val fileStack: Deque<String> = ArrayDeque()
private val importedNames = mutableSetOf<JsName>()
fun serialize(fragment: JsProgramFragment, output: OutputStream) {
val namesBySignature = fragment.nameBindings.associate { it.key to it.name }
importedNames.clear()
importedNames += fragment.imports.map { namesBySignature[it.key]!! }
serialize(fragment).writeTo(output)
}
@@ -556,6 +560,10 @@ class JsAstSerializer(private val pathResolver: (File) -> String) {
builder.localNameId = serialize(it)
}
if (name.imported && name !in importedNames) {
builder.imported = true
}
val result = nameTableBuilder.entryCount
nameTableBuilder.addEntry(builder)
result