@@ -722,16 +722,26 @@ class TS2ASParser
722
722
} ) ;
723
723
}
724
724
725
- private mergeInterfaceAndVariable ( interfaceDefinition : as3 . InterfaceDefinition , variableDeclaration : ts . VariableDeclaration )
725
+ private mergeInterfaceAndVariable ( interfaceDefinition : as3 . InterfaceDefinition , variableDefinition : as3 . PackageVariableDefinition )
726
726
{
727
- let variableAccessLevel = this . getAccessLevel ( variableDeclaration ) ;
728
727
let as3Class = new as3 . ClassDefinition ( interfaceDefinition . name ,
729
- interfaceDefinition . packageName , variableAccessLevel ,
728
+ interfaceDefinition . packageName , variableDefinition . accessLevel ,
730
729
interfaceDefinition . sourceFile , interfaceDefinition . require ,
731
730
this . _currentFileIsExternal ) ;
732
731
733
732
let index = this . _definitions . indexOf ( interfaceDefinition ) ;
734
- this . _definitions [ index ] = as3Class ;
733
+ if ( index >= 0 )
734
+ {
735
+ this . _definitions [ index ] = as3Class ;
736
+ return ;
737
+ }
738
+ index = this . _definitions . indexOf ( variableDefinition ) ;
739
+ if ( index >= 0 )
740
+ {
741
+ this . _definitions [ index ] = as3Class ;
742
+ return ;
743
+ }
744
+ throw new Error ( "Cannot find existing definition to replace, with name " + as3Class . getFullyQualifiedName ( ) ) ;
735
745
}
736
746
737
747
private populateTypeParameters ( declaration : ts . Declaration ) : string [ ]
@@ -878,7 +888,17 @@ class TS2ASParser
878
888
return null ;
879
889
}
880
890
}
881
- return new as3 . InterfaceDefinition ( interfaceName , packageName , this . getAccessLevel ( interfaceDeclaration ) , this . _currentSourceFile . fileName , this . _currentModuleNeedsRequire , this . _currentFileIsExternal ) ;
891
+ let as3Interface = new as3 . InterfaceDefinition ( interfaceName , packageName , this . getAccessLevel ( interfaceDeclaration ) , this . _currentSourceFile . fileName , this . _currentModuleNeedsRequire , this . _currentFileIsExternal ) ;
892
+
893
+ let existingDefinition = as3 . getDefinitionByName ( fullyQualifiedInterfaceName , this . _definitions ) ;
894
+ if ( existingDefinition instanceof as3 . PackageVariableDefinition )
895
+ {
896
+ //this is a decomposed class where the variable name and the
897
+ //instance side have the same name
898
+ this . mergeInterfaceAndVariable ( as3Interface , existingDefinition ) ;
899
+ return null ;
900
+ }
901
+ return as3Interface ;
882
902
}
883
903
884
904
private populateInterface ( interfaceDeclaration : ts . InterfaceDeclaration )
@@ -989,26 +1009,28 @@ class TS2ASParser
989
1009
{
990
1010
fullyQualifiedName = packageName + "." + variableName ;
991
1011
}
1012
+ let accessLevel = this . getAccessLevel ( variableDeclaration ) ;
992
1013
let existingDefinition = as3 . getDefinitionByName ( fullyQualifiedName , this . _definitions ) ;
993
- if ( existingDefinition instanceof as3 . InterfaceDefinition )
1014
+ if ( existingDefinition instanceof as3 . StaticSideClassDefinition )
994
1015
{
995
- //this is a decomposed class where the variable name and the
996
- //instance side have the same name
997
- this . mergeInterfaceAndVariable ( existingDefinition , variableDeclaration ) ;
1016
+ //this is a decomposed class where the variable name and the static
1017
+ //side have the same name
1018
+ existingDefinition . accessLevel = accessLevel ;
998
1019
return null ;
999
1020
}
1000
- else if ( existingDefinition instanceof as3 . StaticSideClassDefinition )
1021
+ let as3Variable = new as3 . PackageVariableDefinition ( variableName , packageName , accessLevel , this . _currentSourceFile . fileName , this . _currentModuleNeedsRequire , this . _currentFileIsExternal ) ;
1022
+ if ( existingDefinition instanceof as3 . InterfaceDefinition )
1001
1023
{
1002
- //this is a decomposed class where the variable name and the static
1003
- //side have the same name
1004
- existingDefinition . accessLevel = this . getAccessLevel ( variableDeclaration ) ;
1024
+ //this is a decomposed class where the variable name and the
1025
+ //instance side have the same name
1026
+ this . mergeInterfaceAndVariable ( existingDefinition , as3Variable ) ;
1005
1027
return null ;
1006
1028
}
1007
1029
else if ( existingDefinition !== null )
1008
1030
{
1009
1031
throw new Error ( "Definition with name " + fullyQualifiedName + " already exists. Cannot create package variable." ) ;
1010
1032
}
1011
- return new as3 . PackageVariableDefinition ( variableName , packageName , this . getAccessLevel ( variableDeclaration ) , this . _currentSourceFile . fileName , this . _currentModuleNeedsRequire , this . _currentFileIsExternal ) ;
1033
+ return as3Variable ;
1012
1034
}
1013
1035
1014
1036
private populatePackageVariable ( variableDeclaration : ts . VariableDeclaration )
0 commit comments