Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Fix declare class with qualified type identifier #97

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pp.flowParseInterfaceish = function (node, allowStatic) {
pp.flowParseInterfaceExtends = function () {
let node = this.startNode();

node.id = this.parseIdentifier();
node.id = this.flowParseQualifiedTypeIdentifier();
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterInstantiation();
} else {
Expand Down Expand Up @@ -394,19 +394,27 @@ pp.flowObjectTypeSemicolon = function () {
}
};

pp.flowParseGenericType = function (startPos, startLoc, id) {
let node = this.startNodeAt(startPos, startLoc);

node.typeParameters = null;
node.id = id;
pp.flowParseQualifiedTypeIdentifier = function (startPos, startLoc, id) {
startPos = startPos || this.state.start;
startLoc = startLoc || this.state.startLoc;
let node = id || this.parseIdentifier();

while (this.eat(tt.dot)) {
let node2 = this.startNodeAt(startPos, startLoc);
node2.qualification = node.id;
node2.qualification = node;
node2.id = this.parseIdentifier();
node.id = this.finishNode(node2, "QualifiedTypeIdentifier");
node = this.finishNode(node2, "QualifiedTypeIdentifier");
}

return node;
};

pp.flowParseGenericType = function (startPos, startLoc, id) {
let node = this.startNodeAt(startPos, startLoc);

node.typeParameters = null;
node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id);

if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterInstantiation();
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/flow/declare-statements/16/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare class A extends C.B.D { }
185 changes: 185 additions & 0 deletions test/fixtures/flow/declare-statements/16/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"type": "File",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 33
}
},
"program": {
"type": "Program",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 33
}
},
"sourceType": "module",
"body": [
{
"type": "DeclareClass",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 33
}
},
"id": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "A"
},
"name": "A"
},
"typeParameters": null,
"extends": [
{
"type": "InterfaceExtends",
"start": 24,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 29
}
},
"id": {
"type": "QualifiedTypeIdentifier",
"start": 24,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 29
}
},
"qualification": {
"type": "QualifiedTypeIdentifier",
"start": 24,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 27
}
},
"qualification": {
"type": "Identifier",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 25
},
"identifierName": "C"
},
"name": "C"
},
"id": {
"type": "Identifier",
"start": 26,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 27
},
"identifierName": "B"
},
"name": "B"
}
},
"id": {
"type": "Identifier",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "D"
},
"name": "D"
}
},
"typeParameters": null
}
],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start": 30,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 33
}
},
"callProperties": [],
"properties": [],
"indexers": []
}
}
],
"directives": []
}
}