Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Parser: added support for decomposed class where variable appears bef…
Browse files Browse the repository at this point in the history
…ore interface with same name (previously only handled interface before variable)
  • Loading branch information
joshtynjala committed Sep 4, 2015
1 parent 30f7121 commit d7d692d
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions source/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,26 @@ class TS2ASParser
});
}

private mergeInterfaceAndVariable(interfaceDefinition: as3.InterfaceDefinition, variableDeclaration: ts.VariableDeclaration)
private mergeInterfaceAndVariable(interfaceDefinition: as3.InterfaceDefinition, variableDefinition: as3.PackageVariableDefinition)
{
let variableAccessLevel = this.getAccessLevel(variableDeclaration);
let as3Class = new as3.ClassDefinition(interfaceDefinition.name,
interfaceDefinition.packageName, variableAccessLevel,
interfaceDefinition.packageName, variableDefinition.accessLevel,
interfaceDefinition.sourceFile, interfaceDefinition.require,
this._currentFileIsExternal);

let index = this._definitions.indexOf(interfaceDefinition);
this._definitions[index] = as3Class;
if(index >= 0)
{
this._definitions[index] = as3Class;
return;
}
index = this._definitions.indexOf(variableDefinition);
if(index >= 0)
{
this._definitions[index] = as3Class;
return;
}
throw new Error("Cannot find existing definition to replace, with name " + as3Class.getFullyQualifiedName());
}

private populateTypeParameters(declaration: ts.Declaration): string[]
Expand Down Expand Up @@ -878,7 +888,17 @@ class TS2ASParser
return null;
}
}
return new as3.InterfaceDefinition(interfaceName, packageName, this.getAccessLevel(interfaceDeclaration), this._currentSourceFile.fileName, this._currentModuleNeedsRequire, this._currentFileIsExternal);
let as3Interface = new as3.InterfaceDefinition(interfaceName, packageName, this.getAccessLevel(interfaceDeclaration), this._currentSourceFile.fileName, this._currentModuleNeedsRequire, this._currentFileIsExternal);

let existingDefinition = as3.getDefinitionByName(fullyQualifiedInterfaceName, this._definitions);
if(existingDefinition instanceof as3.PackageVariableDefinition)
{
//this is a decomposed class where the variable name and the
//instance side have the same name
this.mergeInterfaceAndVariable(as3Interface, existingDefinition);
return null;
}
return as3Interface;
}

private populateInterface(interfaceDeclaration: ts.InterfaceDeclaration)
Expand Down Expand Up @@ -989,26 +1009,28 @@ class TS2ASParser
{
fullyQualifiedName = packageName + "." + variableName;
}
let accessLevel = this.getAccessLevel(variableDeclaration);
let existingDefinition = as3.getDefinitionByName(fullyQualifiedName, this._definitions);
if(existingDefinition instanceof as3.InterfaceDefinition)
if(existingDefinition instanceof as3.StaticSideClassDefinition)
{
//this is a decomposed class where the variable name and the
//instance side have the same name
this.mergeInterfaceAndVariable(existingDefinition, variableDeclaration);
//this is a decomposed class where the variable name and the static
//side have the same name
existingDefinition.accessLevel = accessLevel;
return null;
}
else if(existingDefinition instanceof as3.StaticSideClassDefinition)
let as3Variable = new as3.PackageVariableDefinition(variableName, packageName, accessLevel, this._currentSourceFile.fileName, this._currentModuleNeedsRequire, this._currentFileIsExternal);
if(existingDefinition instanceof as3.InterfaceDefinition)
{
//this is a decomposed class where the variable name and the static
//side have the same name
existingDefinition.accessLevel = this.getAccessLevel(variableDeclaration);
//this is a decomposed class where the variable name and the
//instance side have the same name
this.mergeInterfaceAndVariable(existingDefinition, as3Variable);
return null;
}
else if(existingDefinition !== null)
{
throw new Error("Definition with name " + fullyQualifiedName + " already exists. Cannot create package variable.");
}
return new as3.PackageVariableDefinition(variableName, packageName, this.getAccessLevel(variableDeclaration), this._currentSourceFile.fileName, this._currentModuleNeedsRequire, this._currentFileIsExternal);
return as3Variable;
}

private populatePackageVariable(variableDeclaration: ts.VariableDeclaration)
Expand Down

0 comments on commit d7d692d

Please sign in to comment.