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

Commit 4083f14

Browse files
committed
parser: fixed issue with optional members in interfaces becoming required in ActionScript
1 parent 636efde commit 4083f14

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

source/parser.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,10 @@ export default class
22552255
//this property can be ignored
22562256
return null;
22572257
}
2258+
if(propertyDeclaration.questionToken)
2259+
{
2260+
return null;
2261+
}
22582262
let isStatic = false;
22592263
if(propertyDeclaration.modifiers)
22602264
{
@@ -2281,6 +2285,10 @@ export default class
22812285
//this property can be ignored
22822286
return;
22832287
}
2288+
if(propertyDeclaration.questionToken)
2289+
{
2290+
return null;
2291+
}
22842292
let isStatic = false;
22852293
if(propertyDeclaration.modifiers)
22862294
{
@@ -2441,6 +2449,10 @@ export default class
24412449
//this method can be ignored
24422450
return null;
24432451
}
2452+
if(functionDeclaration.questionToken)
2453+
{
2454+
return null;
2455+
}
24442456
let isStatic = false;
24452457
if(functionDeclaration.modifiers)
24462458
{
@@ -2468,6 +2480,10 @@ export default class
24682480
//this method can be ignored
24692481
return;
24702482
}
2483+
if(functionDeclaration.questionToken)
2484+
{
2485+
return null;
2486+
}
24712487
let typeParameters = this.populateTypeParameters(functionDeclaration);
24722488
let isStatic = false;
24732489
if(functionDeclaration.modifiers)
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export interface InterfaceWithOptionalMembers
22
{
3-
method1(): number;
4-
method2?(): boolean;
5-
}
6-
7-
export class ClassImplementsInterfaceWithOptionalMembers implements InterfaceWithOptionalMembers
8-
{
9-
method1();
3+
method1?(): number;
4+
method2(): boolean;
105
}

spec/parser/parser-spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ describe("An interface", () =>
459459
let as3MethodType = <as3.TypeDefinition> as3.getDefinitionByName("Number", symbols);
460460
expect(method.type).toBe(as3MethodType);
461461
});
462+
it("must skip optional methods", () =>
463+
{
464+
let symbols = parser.parse(["spec/fixtures/interface-optional-members.d.ts"]).definitions;
465+
let as3Interface = <as3.TypeDefinition> as3.getDefinitionByName("InterfaceWithOptionalMembers", symbols);
466+
expect(as3Interface).not.toBeNull();
467+
expect(as3Interface.methods.length).toBe(1);
468+
let method = as3Interface.methods[0];
469+
expect(method).not.toBeNull();
470+
expect(method.name).toBe("method2");
471+
expect(method.accessLevel).toBeNull();
472+
expect(method.isStatic).toBe(false);
473+
let as3MethodType = <as3.TypeDefinition> as3.getDefinitionByName("Boolean", symbols);
474+
expect(method.type).toBe(as3MethodType);
475+
});
462476
it("may extend another interface", () =>
463477
{
464478
let symbols = parser.parse(["spec/fixtures/interface-extends-interface.d.ts"]).definitions;

0 commit comments

Comments
 (0)