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

Commit

Permalink
parser: fixed issue with optional members in interfaces becoming requ…
Browse files Browse the repository at this point in the history
…ired in ActionScript
  • Loading branch information
joshtynjala committed Jul 14, 2017
1 parent 636efde commit 4083f14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
16 changes: 16 additions & 0 deletions source/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,10 @@ export default class
//this property can be ignored
return null;
}
if(propertyDeclaration.questionToken)
{
return null;
}
let isStatic = false;
if(propertyDeclaration.modifiers)
{
Expand All @@ -2281,6 +2285,10 @@ export default class
//this property can be ignored
return;
}
if(propertyDeclaration.questionToken)
{
return null;
}
let isStatic = false;
if(propertyDeclaration.modifiers)
{
Expand Down Expand Up @@ -2441,6 +2449,10 @@ export default class
//this method can be ignored
return null;
}
if(functionDeclaration.questionToken)
{
return null;
}
let isStatic = false;
if(functionDeclaration.modifiers)
{
Expand Down Expand Up @@ -2468,6 +2480,10 @@ export default class
//this method can be ignored
return;
}
if(functionDeclaration.questionToken)
{
return null;
}
let typeParameters = this.populateTypeParameters(functionDeclaration);
let isStatic = false;
if(functionDeclaration.modifiers)
Expand Down
9 changes: 2 additions & 7 deletions spec/fixtures/interface-optional-members.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
export interface InterfaceWithOptionalMembers
{
method1(): number;
method2?(): boolean;
}

export class ClassImplementsInterfaceWithOptionalMembers implements InterfaceWithOptionalMembers
{
method1();
method1?(): number;
method2(): boolean;
}
14 changes: 14 additions & 0 deletions spec/parser/parser-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ describe("An interface", () =>
let as3MethodType = <as3.TypeDefinition> as3.getDefinitionByName("Number", symbols);
expect(method.type).toBe(as3MethodType);
});
it("must skip optional methods", () =>
{
let symbols = parser.parse(["spec/fixtures/interface-optional-members.d.ts"]).definitions;
let as3Interface = <as3.TypeDefinition> as3.getDefinitionByName("InterfaceWithOptionalMembers", symbols);
expect(as3Interface).not.toBeNull();
expect(as3Interface.methods.length).toBe(1);
let method = as3Interface.methods[0];
expect(method).not.toBeNull();
expect(method.name).toBe("method2");
expect(method.accessLevel).toBeNull();
expect(method.isStatic).toBe(false);
let as3MethodType = <as3.TypeDefinition> as3.getDefinitionByName("Boolean", symbols);
expect(method.type).toBe(as3MethodType);
});
it("may extend another interface", () =>
{
let symbols = parser.parse(["spec/fixtures/interface-extends-interface.d.ts"]).definitions;
Expand Down

0 comments on commit 4083f14

Please sign in to comment.